Share your repls and programming experiences

← Back to all posts
Java program to add two numbers taking input from user
RaghunathThilag (1)

ava program to add two numbers taking input from user, this is will receive the input from the user and perform addition of two numbers in java. In this program you will learn how to write a addition of two numbers in java program. This software can combine two separate numbers into a single number. Here’s a java program for beginners in the java program that does addition with the third variable.

import java.util.Scanner;
public class Main
{

public static void main(String[] args)
{

int a, b, sum;
Scanner sc = new Scanner(System.in);
System.out.println("Enter First Number: ");
a = sc.nextInt();
System.out.println("Enter Second Number: ");
b = sc.nextInt();
sc.close();
sum = a + b;
System.out.println("Sum of these numbers: "+sum);
}
}
Output

The sum is 300

Source: https://inlarn.com/java-program-to-add-two-numbers-taking-input-from-user/