This question has already been answered:
There is the following code:
String tmp="string"; Scanner sc = new Scanner(System.in); while (true) { //some code switch (sc.nextInt()) { case 1: ... case 2: ... case 3: ... case 4: System.out.print("Введите критерий: "); tmp = sc.nextLine(); System.out.println("tmp= " + tmp); break; } So, after entering 4 and, accordingly, moving to case 4: I am not offered to enter a string, but simply write an empty string in tmp and the program moves to the next iteration. I read about Scanner on different sites, but did not understand the peculiarity of his work, because of which I had this incident. Explain, please.
sc.nextLine();beforetmp = sc.nextLine();so that wasSystem.out.print("Введите критерий: "); sc.nextLine(); tmp = sc.nextLine(); System.out.println("tmp= " + tmp); break;System.out.print("Введите критерий: "); sc.nextLine(); tmp = sc.nextLine(); System.out.println("tmp= " + tmp); break;- Alexey Shimansky