Keyboard input interface in Java for Desktop Application


/ Published in: Java
Save to your folder(s)

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


Copy this code and paste it in your HTML
  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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.