fork download
  1. import java.io.*;
  2.  
  3. class GetUserInput{
  4.  
  5. public static void main(String[] args){
  6.  
  7. //the data that will be entered by the user
  8. String name;
  9. int a;
  10.  
  11. //an instance of the BufferedReader class
  12. //will be used to read the data
  13. BufferedReader reader;
  14.  
  15. //specify the reader variable
  16. //to be a standard input buffer
  17. reader = new BufferedReader(new InputStreamReader(System.in));
  18.  
  19. //ask the user for their name
  20. System.out.print("What is your name? ");
  21.  
  22. try{
  23.  
  24. //read the data entered by the user using
  25. //the readLine() method of the BufferedReader class
  26. //and store the value in the name variable
  27. name = reader.readLine();
  28.  
  29. //print the data entered by the user
  30. System.out.println("Your name is " + name);
  31.  
  32. }
  33.  
  34. catch (IOException ioe){
  35.  
  36. //statement to execute if an input/output exception occurs
  37. System.out.println("An unexpected error occured.");
  38. try{
  39. a = reader.readLine90;
  40. System.out.println("Your age is:" + a);
  41. }
  42. catch (IOException ioe){
  43.  
  44. //statement to execute if an input/output exception occurs
  45. System.out.println("An unexpected error occured.");
  46.  
  47.  
  48.  
  49. }
  50. }
  51. }
Success #stdin #stdout 0.01s 1704KB
stdin
Standard input is empty
stdout