My if-then-else
statement is always outputting the else
outcome
import java.util.Scanner;
public class NiallScanner {
public static void main(String[] args)
{
System.out.println("Hello, What is your name?");
Scanner scanner = new Scanner(System.in);
String yourName = scanner.nextLine();
System.out.println("Is your name: "+yourName + "?");
Scanner scanner1 = new Scanner(System.in);
String isCorrect = scanner1.nextLine();
if (isCorrect == "Yes")
{
System.out.println("Thank you for your confirmation!");
}
else
{
System.out.println("Retry please.");
}
}
Any ideas why guys? I'm really new to java btw, so I may be overlooking basic coding errors.