mercredi 25 mars 2015

Scanner.equals() returns false in either case


package harry;

import java.util.Scanner;

public class harry {

public static void main(String[] args) {

String Harr = ("Harry");

Scanner name = new Scanner(System.in);

System.out.println("Enter your name");

name.nextLine();

if(name.equals("Harry")) {

System.out.println("She hates you");

} else if (name.equals("Nick")) {

System.out.println("She loves you");
}

}

}


In this code, I am trying to write if the name is Harry, it will say "She hates you", but if it says Nick, it will say "she loves you", but when I write on of either names, it doesn't print anything.


Aucun commentaire:

Enregistrer un commentaire