Answer the question
In order to leave comments, you need to log in
Why can't exit the loop?
Hello, why can't you exit the loop when you enter, string
and if you replace it with int
- does everything work?
DOES NOT WORK:
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
boolean isNotEnough = true;
do {
System.out.println("Please enter the question:");
String question = sc.nextLine();
if(question=="out"){
isNotEnough=false;
}
}
while(isNotEnough);
System.out.println("Thanks");
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
boolean isNotEnough = true;
do {
System.out.println("Please enter the question:");
int question = sc.nextInt();
if (question==1){
isNotEnough=false;
}
}
while(isNotEnough);
System.out.println("Thanks");
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question