header ads

Taking input in Java | Scanner class

In this blog I will show you how to take input from the user in java using Scanner class. The example is given below


import java.util.Scanner;                   //header file of scanner 
class demo
{
public static void main(String[] args)
{
Scanner reader =new Scanner(System.in);           //creating object
System.out.println("Enter your name");
String name=reader.nextLine();                   // reading the line and store                                                                                   in name variable
System.out.println(name);                          //print the variable 
}
}



If you want more java program just comment below

Post a Comment

0 Comments