Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- import java.io.*;
- class Main{
- public static void main(String args[]) throws IOException{
- // creating input handler objects
- Scanner sc = new Scanner(System.in);
- BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
- // creating variables
- int choice=0;
- String input="";
- while (true) {
- System.out.println("1. Console Input");
- System.out.println("2. Scanner Input");
- System.out.println("3. BufferReader Input");
- System.out.println("4. DataInputStream Input");
- System.out.println("5. Exit");
- System.out.print("\nEnter choice : ");
- choice = sc.nextInt();
- if (choice == 1) {
- System.out.print("Enter something : ");
- input = System.console().readLine();
- System.out.println(input);
- }
- else if (choice == 2) {
- System.out.print("Enter something : ");
- sc.nextLine();
- input = sc.nextLine();
- System.out.println(input);
- }
- else if (choice == 3){
- System.out.print("Enter something : ");
- input = reader.readLine();
- System.out.println(input);
- }
- System.out.println();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement