Q:

Java program for Addition of Two Numbers

0

Java program for Addition of Two Numbers

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

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 

 

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Core Java Example programs for Beginners and Professionals

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
Java program to print numbers from 1 to 10 using f... >>
<< Java program for Calculator - Design calculator wi...