I have a small task that allows the user to enter the regions and their neighbors of any country.
I did everything and I just have a small problem which is when I run my code and the program asks the user to enter the number of regions, if the user enters 13 or and number greater than 10, the system will consider that number is like two inputs and it will not allow the user to enter anything for the second question and it will prompt him with the third question immediately. Why?
I think the problem with the Scanner class in the following command:
Scanner kb = new Scanner(System.in);
System.out.print("Please enter the number of regions: ");
int REGION_COUNT = kb.nextInt();
region = new CountryRegion[REGION_COUNT];
String[] neighbours;
for (int r = 0; r < region.length; r++) {
System.out.print("Please enter the name of region #" + (r + 1) + ": ");
String regionName = kb.nextLine();
System.out.print("How many neighbors for region #" + (r + 1) + ": ");
if (kb.hasNextInt()) {
int size = kb.nextInt();
neighbours = new String[size];
for (int n = 0; n < size; n++) {
System.out.print("Please enter the neighbour #" + (n + 1) + ": ");
neighbours [n] = kb.nextLine();
}
region [r] = new CountryRegion(regionName, neighbours);
}
else
System.exit(0);
}
for (int i = 0; i < REGION_COUNT; i++) {
System.out.print(region[i].getRegionName() +": ");
for (int k = 0; k < region[i].getRegionAjesint().length; k++) {
System.out.print(region[i].getRegionAjesint()[k] +", ");
}
System.out.println();
}
mapColor = new MapColor(region);
Any help, please?