Ask Me Help Desk

Ask Me Help Desk (https://www.askmehelpdesk.com/forum.php)
-   Java (https://www.askmehelpdesk.com/forumdisplay.php?f=440)
-   -   Java if problem (https://www.askmehelpdesk.com/showthread.php?t=784480)

  • Feb 15, 2014, 05:19 AM
    uneebmir
    Java if problem
    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 */
  • Mar 5, 2014, 07:48 AM
    Aftershock
    try this:
    if(check.toLowerCase()=="yes"){
    System.out.println(" First Name: "+Fname);
    System.out.println(" First Name: "+Lname);
    System.out.println(" First Name: "+EID);
    }

  • All times are GMT -7. The time now is 04:53 PM.