Vadim Vadim - 5 months ago 9x
Java Question

Java if statement (beginner request)

If someone can help me with this. I'm complete -n o o b, only started to learn and got stuck.

If I'm asking this -

Scanner buck = new Scanner(;
String fname;
System.out.println("Please Enter your Name ");
fname =;

which command do I use to make specific name only to be entered as an answer.
For example name would be Vani.

If name is "Vani" than "you are in".
If any else name "than you go out".

I understand this with numbers but not with letters.
Any help would be appreciated.


if ("Vani".equals(fName)) { // you go in } else { // cannot go in }

And if you want case insensitive check, do "Vani".equalsIgnoreCase(fName)