rankz_VtujUdhflsoFhdgp Java User Input (Scanner) - All type study material

Java programming

Java programming

About Me

my self - Harvendra Singh

Search This Blog

Thursday, February 27, 2020

Java User Input (Scanner)

Java User Input (Scanner) -

    

  •  The Scanner class is used to get user input, and it is found in the java.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 the nextLine() method, which is used to read Strings:

                                       
https://Erhsmathur.blogspot.com 

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
               

4 comments: