This question already has an answer here:
- How do I compare strings in Java? 23 answers
import java.util.Scanner;
public class testIf {
public static void main(String[] args) {
System.out.println("Hello");
// Declaring scanner
Scanner scanner = new Scanner(System.in);
// I type in hi in to the console
String greeting = scanner.nextLine();
//Checking input
if (greeting == "hi")
{
System.out.println("good");
}
else
{
System.out.println("bad");
}
}
}
// output: bad`enter code here
Aucun commentaire:
Enregistrer un commentaire