0
I want to use "System.out.print();" to get input from users. How can I define the input as a string so that I can use if statement to check whether the input is equal to a word I set like "red"
2 Answers
+ 1
create a obj scanner to receive the input and compare with method equals().
Scanner in = new Scanner(System.in);//import java.util.Scanner
System.out.println("yes/no");
String input = in.nextLine();
if(input.equals("yes")){...}else{...}
0
thx