Ask Experts Questions for FREE Help !
Ask
    uneebmir's Avatar
    uneebmir Posts: 1, Reputation: 1
    New Member
     
    #1

    Feb 15, 2014, 05:19 AM
    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 */
    Aftershock's Avatar
    Aftershock Posts: 2, Reputation: 1
    New Member
     
    #2

    Mar 5, 2014, 07:48 AM
    try this:
    if(check.toLowerCase()=="yes"){
    System.out.println(" First Name: "+Fname);
    System.out.println(" First Name: "+Lname);
    System.out.println(" First Name: "+EID);
    }

Not your question? Ask your question View similar questions

 

Question Tools Search this Question
Search this Question:

Advanced Search

Add your answer here.


Check out some similar questions!

Java [ 0 Answers ]

Please tell me how actually JVM works and why we are not creating any object to main method class ,then how it will be invoked by the compiler

Java netbeans program- Connection between java and mysql,How to conn [ 0 Answers ]

which I wrote from a book but when I run it, it shows exception please give me the code to connect jlistbox to database when I click on btn1. btn coding should search "name" in database and shows all the names in listbox my coding: here-- r1,r2,r3 are radio btns and l1,l2,l3 are labels,...

Java Swing Problem [ 2 Answers ]

A JComboBox has constructors that can take a Vector or a ComboBoxModel. When I pass a DefaultComboBoxModel to it, and change the contents of the DefaultComboBoxModel, the drop-down list changes as expected. No problem. However, if I pass a Vector to it and change the contents of the...


View more questions Search