String PA; Scanner in = new Scanner(System.in, "Cp866"); PA = in.nextLine(); 

I can not find out the value of PA if, when typing, I press Enter without typing anything.

I tried if(PA == "") out.print("=="); if(PA == null) out.print("=="); Set null when declaring.

Solved the problem by checking the isEmpty () string.

1 answer 1

The point is that you compare strings by reference . An expression of the form str=="" for the string that was read from the console will always give false
For the desired result, you must use either the equals method or isEmpty

  • And what is the value of the variable? Null or empty ("")? IsEmpty? - aaa
  • my empty line came - Artem Konovalov
  • Managed to check on isEmpty - aaa
  • That is, with if you can check the variable to false? - aaa
  • of course, if write if (! false) ... - Artem Konovalov