sarath280

Untitled

Oct 1st, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.15 KB | None | 0 0
  1. import java.io.*;
  2. import java.util.*;
  3.  
  4. public class UserInputConsoleDemo {
  5.  
  6. public static void main(String[] args) {
  7.  
  8. // using InputStreamReader
  9. try {
  10. BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
  11. System.out.print("Enter your name: ");
  12.  
  13. String name = reader.readLine();
  14. System.out.println("Your name is: " + name);
  15. } catch (IOException ioe) {
  16. ioe.printStackTrace();
  17. }
  18.  
  19.  
  20.  
  21. // using Console
  22. Console console = System.console();
  23. if (console == null) {
  24. System.out.println("No console: not in interactive mode!");
  25. System.exit(0);
  26. }
  27.  
  28. System.out.print("Enter your username: ");
  29. String username = console.readLine();
  30.  
  31. System.out.print("Enter your password: ");
  32. char[] password = console.readPassword();
  33.  
  34. System.out.println("Thank you!");
  35. System.out.println("Your username is: " + username);
  36. System.out.println("Your password is: " + String.valueOf(password));
  37.  
  38.  
  39. }
  40. }
Add Comment
Please, Sign In to add comment