Addition of two numbers

Program Description

This short program demonstrates,how to accept integer inputs from the user and perform arithmetic addition in java.

Like addition, other common arithmetic operations like subtraction,multiplication division,modulo ,etc can be performed in the same manner by using the appropriate symbols for those.

Program
/*******************************
*   Addition of two numbers
*	
*    code.cheraus.com
**********************************/

import java.util.Scanner;

class add {
	   public static void main(String args[])
	   {
		   Scanner getNum = new Scanner(System.in);
		   int num1,num2,num3;
		   System.out.println("Enter the First Number : ");
		   num1 = getNum.nextInt();
		   System.out.println("Enter the Second Number : ");
		   num2 = getNum.nextInt();
		   num3 = num2+num1;
		   
		   //here "+" operator concatenates the strings
		   System.out.println("The result is " + num3);
	   }

}

Output
Test Case 1:

Enter the First Number :
23
Enter the Second Number :
23
The result is 46

Test Case 2:

Enter the First Number :
23
Enter the Second Number :
23
The result is 46

Test Case 3:

Enter the First Number :
3
Enter the Second Number :
2
The result is 5

Comments
comments powered by Disqus