0

How can I do this??

I want to ask the user a question such as "Do you like apples?" and then use an if statement. If they enter "Yes" the console will say "So do I" but if they say no or else the console will say "Thats a shame". How would I do this. My current code (but it doesnt work): System.out.println("Do you like apples?"); Scanner myVar = new Scanner(System.in); if (myVar == "Yes") { System.out.println("So do I!"); } else { System.out.println("That's a shame."); }

10th Apr 2017, 3:24 PM
Hapax42
Hapax42 - avatar
1 ответ
+ 12
add an input: import java.util.*; public class Apples { public static void main(String[]args) { String str; Scanner myVar = new Scanner(System.in); System.out.println("Do you like apples?"); str = myVar.nextLine(); if (myVar == "Yes") { System.out.println("So do I!"); } else { System.out.println("That's a shame."); } } }
10th Apr 2017, 3:41 PM
Dev
Dev - avatar