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"

16th Oct 2016, 8:06 AM
Cheung Kim Fung
Cheung Kim Fung - avatar
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{...}
16th Oct 2016, 9:32 AM
Wanderlei Borges
Wanderlei Borges - avatar
0
thx
16th Oct 2016, 9:39 AM
Cheung Kim Fung
Cheung Kim Fung - avatar