vendredi 2 janvier 2015

Boolean statement with String condition? [duplicate]


This question already has an answer here:




When I try something like this:



import java.util.Scanner;
public class Fruits {

public static void main (String[] args){

System.out.println("Would you like to make a Fruit? (Yes/No)");
Scanner input = new Scanner(System.in);
String Input = input.nextLine();

if (Input == "Yes"){

System.out.println("Okay");
}

else{
System.out.println("Ok");
}

}
}


The program always outputs "Ok" even if I type in "Yes" as the input. What mistake am I making?


Aucun commentaire:

Enregistrer un commentaire