Scanner Class
It is a method of getting user's input from the keyboard.
It is found in java.util package.
How to declare java scanner class method?
Scanner in=new Scanner(System.in);
How to add two numbers using scanner class method?
import java.util.Scanner;
class Sibani
{
public static void main(String args[])
{
int a,b,sum=0;
Scanner sc = new Scanner(System.in);
System.out.println("Enter the first number");
a=sc.nextInt();
System.out.println("Enter the seecond number");
b=sc.nextInt();
sum= a+b;
System.out.println("addition is"+sum);
}
}
No comments:
Post a Comment