Home »
Java Programs »
Core Java Example Programs
Java program for Addition of Two Numbers
Java - Read two integer numbers and find their addition
This program will read two integer numbers and find their addition. In this program we will enter two integer numbers and read them using scanner class and then calculate their addition.
Add two numbers using Java Program
/*Java program for Addition of Two Numbers.*/
import java.util.*;
public class AddTwoNum{
public static void main(String []args){
int a,b,add;
/*scanner class object to read values*/
Scanner buf=new Scanner(System.in);
System.out.print("Enter first number: ");
a=buf.nextInt();
System.out.print("Enter second number: ");
b=buf.nextInt();
add= a+b;
System.out.println("Addition is: " + add);
}
}
Output
me@linux:~$ javac AddTwoNum.java
me@linux:~$ java AddTwoNum
Enter first number: 10
Enter second number: 20
Addition is: 30
Core Java Example Programs »