Answer the question
In order to leave comments, you need to log in
Why does the instruction in Java not work correctly?
import java.util.Scanner;
public class test {
static public void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("Желаете еще партейку? y/n");
String answer = scanner.nextLine();
if (answer == "yes" || answer == "y") {
System.out.println("ок");
} else {
System.out.println(answer);
System.out.println("Не правильно");
}
}
}
Answer the question
In order to leave comments, you need to log in
Strings are compared using the equals method.
For example: answer.equals("yes") , or even better "yes".equals(answer)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question