To add two numbers where numbers will be given by user. Using Scanner method

using scanner :

 using scanner is one of the way to take inputs from user in java.


Program :

import java.util.Scanner;
class AddScanner
{
public static void main(String [] args)
{
int a,b,c=0;           //declaration
System.out.println("Enter the two numbers);
Scanner s = new Scanner (System.in);
a=s.nextInt();
b=s.nextInt();
c=a+b;
System.out.println("The addition of two number is :"+c);
}
}

No comments:

Post a Comment