Member Avatar for mark.barrera.94

can u help me with this:

public static void main(String[] args) {
    Scanner s = new Scanner(System.in);
    String name;
    System.out.print("What is your name? ");
       if(name.equals("Bob")) {
     System.out.println("Oh hi, Bob. I know you. Good to see you again.");
    name = s.nextLine();
    }
}
}

what can i do?

Recommended Answers

All 2 Replies

You have to initialize your variable name,before you check it into if loop at line 5.
Also equals method is case sensitive, so it exactly matches what you have written into equals( "here" ).

So initialize it before checking.
put your line 7 before line 5.
and see.
i think its useful.

Also mark it solved if you get your answer.
thanks

Please post the full text of the error message that shows where the error happens.
Look at the source line where the error happens and see what variable has a null value and then backtrack in the code to see why that variable does not have a valid non-null value.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.