import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;
public class JavaUserInput {
public static void main(String[] args) throws IOException {
Scanner scanner = new Scanner(System.in);
System.out.print("What is your favorite color? ");
String name = scanner.next();
System.out.println("Your favorite color is: " + name);
System.out.print("You are in good mood true or false ?");
boolean bool = scanner.nextBoolean();
System.out.println("You entered: " + bool);
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
System.out.print("Please enter your name? ");
String name1 = reader.readLine();
System.out.println("Your name is: " + name1);
}
}
Output:
What is your favorite color? b
Your favorite color is: b
You are in good mood true or false ?false
You entered: false
Please enter your name? abc
Your name is: abc
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;
public class JavaUserInput {
public static void main(String[] args) throws IOException {
Scanner scanner = new Scanner(System.in);
System.out.print("What is your favorite color? ");
String name = scanner.next();
System.out.println("Your favorite color is: " + name);
System.out.print("You are in good mood true or false ?");
boolean bool = scanner.nextBoolean();
System.out.println("You entered: " + bool);
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
System.out.print("Please enter your name? ");
String name1 = reader.readLine();
System.out.println("Your name is: " + name1);
}
}
Output:
What is your favorite color? b
Your favorite color is: b
You are in good mood true or false ?false
You entered: false
Please enter your name? abc
Your name is: abc