Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
- import java.util.Scanner; // enter the before the start of any class
- // declare the class here
- // this is an example of how to use the Scanner in a method
- Public static void Username();{
- Scanner Input = new scanner (System.in);
- String username// declaring the username variable
- Scanner un = new Scanner(System.in); // un is just a random variable you can choose any other variable name if you want
- System.out.println("Enter Your Username");
- username = un.next();
- System.out.println("The username you entered is : " + username);}
- import java.util.Scanner;
- // Declare the class here
- // this is an example of how to use the Scanner in a method for an integer input by user
- Public static void booksRead();{
- Scanner Input = new scanner (System.in);
- int books // declaring the books variable
- Scanner br = new Scanner(System.in); // br is just a random variable you can choose any other variable name if you want
- System.out.println("Enter how many books have you read: ");
- books = br.next();
- System.out.println("The number of books you have read is : " + books);}
- This will print the number entered by user :
- Scanner reader = new Scanner(System.in); // Reading from System.in
- System.out.println("Enter a number: ");
- int n = reader.nextInt(); // Scans the next token of the input as an int.
- //once finished
- System.out.println(n);
- reader.close();
- }
Add Comment
Please, Sign In to add comment