Java User Input (Scanner) -
The Scanner
class is used to get user input, and it is found in thejava.util
package.
- To use the scanner class, create an object of the class and use any of the available methods found in the
Scanner
class documentation. In our example, we will use thenextLine()
method, which is used to read Strings:
Example -
import java.util.scanner;
import java.util.*;
class abc
{
public static void main (String args[ ])
{
int a,b,c;
Scanner obj=new Scanner(System.in);
System.out.print("Enter the value of A");
a=obj.nextInt();
System.out.print("Enter the value of B");
b=obj.nextInt();
c=a+b;
System.out.print("The sum is="+c);
}
}
Output - Enter the value of a - 6
Enter the value of a - 5 = 11
Enter the value of a - 5 = 11
Sir notes bahut bhadiya hai
ReplyDeleteSir thank you
ReplyDeleteBhadiya sir ji
ReplyDeleteNice sirji
ReplyDelete