Java program for Addition of Two Numbers

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 »



Related Programs



Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.