1
import java.io.IOException;
import java.util.Scanner;

public class MainTraining {
    public static void main(String[] args) throws IOException {
        Scanner scanner = new Scanner(System.in);
        int countOfStrangers = scanner.nextInt();
        String[] name = new String[countOfStrangers];
        System.out.println(scanner.nextLine());
    }
}

It will output nothing. Why?

that is only first part of my programm, so that separately this code has no sense

dadadaniil
  • 11
  • 2

1 Answers1

0

As i undersood, there are some troubles if you use nextLine after nextInt. To solve this problem you can read int with nextLine and after that parse it to int. Also you can create two scanners: one for ints and one for Strings

Full answer is here: Why can't I enter a string in Scanner(System.in), when calling nextLine()-method?

dadadaniil
  • 11
  • 2