- 1
How can I take the input from user in java?
2 Answers
+ 2
There are 3 classes in java with which you can take input from user:
1.) Scanner Class.
2.) Buffered Reader class.
3.) Console class.
Syntax of all these 3 classes is different but i prefer you to use Buffered Reader class because it is convenient and flexible enough to read whole line with white spaces.
import java.io.IOException;
import java.io.BufferedReader;
class Abc{
public static void main(String arg[])throws IOException{
BufferedReader br= new BufferedReader(new InputStreamReader(System.in));
String name;
System.out.println(" Enter your name: ");
name=br.readLine();
System.out.println(" Welcome Mr. "+name);
}
}