Thursday, 1 February 2018

java - Comparing two identical strings with == returns false

I am making an archive for my family. There are no syntax errors, however whenever I type in "Maaz", it evaluates realName == "Maaz" to false and goes to the else statement.



import java.util.Scanner;

public class MainFamily {
public static void main (String [] args) {

System.out.println("Enter you're name here");

Scanner name = new Scanner(System.in);//Scanner variable = name

String realName;
realName = name.nextLine();//String variable = user input
System.out.println("Name: "+ realName);

if (realName == "Maaz") {

System.out.println("Name: Maaz");


} else {
System.out.println("This person is not in the database");
}
}
}

No comments:

Post a Comment

casting - Why wasn't Tobey Maguire in The Amazing Spider-Man? - Movies & TV

In the Spider-Man franchise, Tobey Maguire is an outstanding performer as a Spider-Man and also reprised his role in the sequels Spider-Man...