This question already has an answer here:
- How do I compare strings in Java? 23 answers
I am trying to scan a string and put it in an if like so: (this is just an example part of the whole program)
Scanner scan=new Scanner();
System.out.print("Enter the word...");
String a=scan.nextLine();
if (a=="Hi")
System.out.println("Hello!")
Else System.exit(0);
So im checking if the user said "Hi" , but it doesnt work like this, I want a way to do it.
I have just started learning java so my questions might seem a little amateur but your answers will help a lot.
Aucun commentaire:
Enregistrer un commentaire