Scanner sc = new Scanner(System.in); // Владелец System.out.print("Владелец: "); String owner = sc.nextLine(); // Номер парковки System.out.print("Номер парковки: "); String number = sc.nextLine(); 

I have to enter a value for the owner and number string, but in the console it displays:

 Владелец: Номер парковки: АЕ-535 --- Вы ввели --- Владелец: Номер парковки: АЕ-535 

and I can enter a value. but this value will be for number only. How then to be?

  • Everything works for me) Can you give a complete example ? Or clarify where and how to run? - default locale
  • Try to display the word "Owner" with the transition to a new line System.out.println or replace nextLine with next - Flippy

1 answer 1

Everything is working. It is only necessary to use correctly and carefully. The values ​​in this example are entered from the keyboard alternately for both owner and number. Most likely, the Enter value was simply pressed for the owner value and the owner value was set to an empty string (a la String owner = ""), so the value for it was not output to the console. Notice that System.out.print () writes the data to the console in one line, and System.out.println () from a new line. The \ n inside the text also provides a new text line.

 public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.print("Владелец: "); String owner = sc.nextLine(); System.out.print("Номер парковки: "); String number = sc.nextLine(); System.out.print ("Владелец: " + owner + " "); System.out.print ("Номер парковки: " + number); System.out.println (); System.out.println ("Владелец: " + owner); System.out.println ("Номер парковки: " + number); System.out.println ("Альтернативный вариант: \nВладелец: " + owner + "\nНомер парковки: " + number ); sc.close(); } Console: Владелец: Я Номер парковки: 1 Владелец: Я Номер парковки: 1 Владелец: Я Номер парковки: 1 Альтернативный вариант: Владелец: Я Номер парковки: 1