import java.util.Scanner;
public class ReturnÜbung_2{
public static String userData(){
Scanner userInput = new Scanner(System.in);
System.out.println("Geben Sie bitte Ihren Namen ein: ");
String name = userInput.nextLine();
System.out.println("Geben Sie bitte Ihren Nachnamen ein: ");
String nachname = userInput.nextLine();
String userInfo;
if (name == "Bangoo" && nachname == "Mangoo")
{
System.out.println("You are cool!!");
userInfo = name + " " + nachname;
} else {
System.out.println("Your are not cool!! ");
userInfo = "Yor are not " + "Bangoo" + " " + "Mangoo";
}
return userInfo;
}
public static void main(String [] args){
String userInfo= userData();
System.out.println(userInfo);
}
}//end of class Return
Can anyone please explain me why my code is not working properly?
The else part is working and the if part is not working. I mean no matter what for an input you give, it always executes the else condition.
And please if possible give me some tips and optimize my code.