samedi 23 juin 2018

How to put a certain string into *if* and check if it is a certain word [duplicate]

This question already has an answer here:

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