ADVERTISEMENT
ADVERTISEMENT

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

    [email protected]:~$ javac AddTwoNum.java
    [email protected]:~$ java AddTwoNum
    Enter first number: 10
    Enter second number: 20 
    Addition is: 30 

Core Java Example Programs »


ADVERTISEMENT
ADVERTISEMENT


Comments and Discussions!



ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.