Guest User

Untitled

a guest
Jan 19th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.43 KB | None | 0 0
  1. BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
  2.  
  3. import java.util.Scanner; // enter the before the start of any class
  4. // declare the class here
  5. // this is an example of how to use the Scanner in a method
  6. Public static void Username();{
  7. Scanner Input = new scanner (System.in);
  8. String username// declaring the username variable
  9. Scanner un = new Scanner(System.in); // un is just a random variable you can choose any other variable name if you want
  10. System.out.println("Enter Your Username");
  11. username = un.next();
  12. System.out.println("The username you entered is : " + username);}
  13.  
  14. import java.util.Scanner;
  15. // Declare the class here
  16. // this is an example of how to use the Scanner in a method for an integer input by user
  17. Public static void booksRead();{
  18. Scanner Input = new scanner (System.in);
  19. int books // declaring the books variable
  20. Scanner br = new Scanner(System.in); // br is just a random variable you can choose any other variable name if you want
  21. System.out.println("Enter how many books have you read: ");
  22. books = br.next();
  23. System.out.println("The number of books you have read is : " + books);}
  24.  
  25. This will print the number entered by user :
  26.  
  27. Scanner reader = new Scanner(System.in); // Reading from System.in
  28. System.out.println("Enter a number: ");
  29. int n = reader.nextInt(); // Scans the next token of the input as an int.
  30. //once finished
  31. System.out.println(n);
  32. reader.close();
  33.  
  34.  
  35. }
Add Comment
Please, Sign In to add comment