How to Read Java Console Input
There are three different ways to read the input from Java Console, they are –
Using Java Bufferedreader Class
Scanner Class in Java
Console Class in Java
Example of Java Bufferedreader Class–
1. import [Link];
2. import [Link];
3. import [Link];
4. public class Test
5. {
6. public static void main(String[] args) throws IOException
7. {
8. BufferedReader reader =
9. new BufferedReader(new InputStreamReader([Link]));
10. String name = [Link]();
11. [Link](name);
12. }
13. }
Scanner Class
1. import [Link];
2. class GetInputFromUser
3. {
4. public static void main(String args[])
5. {
6. Scanner in = new Scanner([Link]);
7. String s = [Link]();
8. [Link]("You entered string "+s);
9. int a = [Link]();
10. [Link]("You entered integer "+a);
11. float b = [Link]();
12. [Link]("You entered float "+b);
13. }
14. }
Console
1. public class Sample
2. {
3. public static void main(String[] args)
4. {
5. // Using Console to input data from user
6. String name = [Link]().readLine();
7. [Link](name);
8. }
9. }