Posted By

akufun on 11/08/09


Tagged

input


Versions (?)

Keyboard input interface in Java for Desktop Application


 / Published in: Java
 

Shows entire way using which input can be taken in java. As such it is a headache to take input in java

  1. import java.io.*;
  2.  
  3. public class ReadString {
  4.  
  5. public static void main (String[] args) {
  6.  
  7. // prompt the user to enter their name
  8. System.out.print("Enter your name: ");
  9.  
  10. // open up standard input
  11.  
  12. String userName = null;
  13.  
  14. // read the username from the command-line; need to use try/catch with the
  15. // readLine() method
  16. try {
  17. userName = br.readLine();
  18. } catch (IOException ioe) {
  19. System.out.println("IO error trying to read your name!");
  20. System.exit(1);
  21. }
  22.  
  23. System.out.println("Thanks for the name, " + userName);
  24.  
  25. }
  26.  
  27. } // end of ReadString class

Report this snippet  

You need to login to post a comment.