How to take input from user in JAVA?


How to take input from user in JAVA?



import java.util.*;                                               
//entire util package is imported

class scan
{
        public static void main(String[] args)
        {
                int x,y;
                Scanner in=new Scanner(System.in);                              //scanner is class name in is object then constructor    part(paramitrize),system.in is paramiter.
                //using new to allocate memory
                System.out.println("enter two value(x,y)=");

                x=in.nextInt();                               //taking int value
                y=in.nextInt();

                System.out.println("x=" +x);
        }
}
// nextLine: take string input
// nextFloat: take float input


Output:
enter two value(x,y)=
41
54

 x=41

How to take input from user in JAVA? How to take input from user in JAVA? Reviewed by Unknown on January 28, 2019 Rating: 5

Post Comments

Programming copyright © 2018-19. Powered by Blogger.