This question already has an answer here:
- How do I compare strings in Java? 23 answers
I would like to know how I could say in Java like if the scanner detects a yes then do this then if not do something else. For instance, I want to say if you type "yes" to this statement then a print line will pop up saying something but if I type "no" then another print line will pop up instead of "yes" result.
System.out.println("What are you're hobbies, " + name + '?');
String hobby = scanner.nextLine();
System.out.println("I like " + hobby + " too!");
System.out.println("Let's go do it together!");
String decision = scanner.nextLine();
if(yes) {
String.out.println("Let's go!")
}
if(no) {
String.out.println("Okay, have a nice day then.")
}
Aucun commentaire:
Enregistrer un commentaire