public class Employee {
public void mainfnt(){
try{
System.out.println("Enter First Name: ");
Scanner obj=new Scanner(System.in);
String Fname=obj.nextLine();
System.out.println("Enter Last Name: ");
String Lname=obj.nextLine();
System.out.println("Enter Employee ID: ");
String EID=obj.nextLine();
System.out.println("Do you want to display user information hit Yes or n: ");
String check=obj.nextLine();
if(check=="Yes"){
System.out.println(" First Name: "+Fname);
System.out.println(" First Name: "+Lname);
System.out.println(" First Name: "+EID);
}
else{
System.out.println("Thankyou");
}
}
catch(Exception e){
System.out.println("Not a valid input");
System.out.println("try again");
Employee obj=new Employee();
obj.mainfnt();
}
}
}/*
I have a problem in the if statement of the code my check variable is of String Scanner type,when in if condition I write if(check=="yes") it does not accepts and condition and moves to false anyone help me out */