Q:

Parallel Arrays, Accepting multiple inputs

I'm currently trying to accept input into two arrays simultaneously. The reason being that the data at each position of the array is corresponding, eg. Name and ID number.
String[] arr = new String[5];
    int[] arr1 = new int[5];

    Scanner kb = new Scanner(System.in);
    for(int i = 0; i<5; i++)
    {
        System.out.println("Enter a name:");
        arr[i] = kb.nextLine();
        System.out.println("Enter an ID:");
        arr1[i] = kb.nextInt();
    }

I have this code so far, but whenever i run it, it asks for a name and ID once then asks for both but only will accept ID.
I cant seem to figure out why it doesnt allow the name to be inputted, it just returns an incompatible data type error for that.

A:

From the second iteration your kb.nextLine() that reads name swallows the \n new line character that is inputted to enter the ID integer.
Actual problem is nextInt() leaves char tokens that are not numeric tokens, so they stay in stdin. Whenever any other method tries to read stdin that method takes that input. nextLine method returns after \n, hence the problem.
So change the code like this:  
String[] arr = new String[5];
        int[] arr1 = new int[5];

        Scanner kb = new Scanner(System.in);
        for(int i = 0; i<5; i++)
        {
            System.out.println("Enter a name:");
            arr[i] = kb.nextLine();
            System.out.println("Enter an ID:");
            arr1[i] = kb.nextInt();
            kb.nextLine();  //now this swallows new line
        }

Or you can use two scanners: If you want there should be no relation as such giving input them...no conflicts not at all... I don't know if that is less efficient.
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.*;

public class Tester {

public static void main(String[] args) throws Exception {

String[] arr = new String[5];
        int[] arr1 = new int[5];

        Scanner kb = new Scanner(System.in);
        Scanner  bc=new Scanner(System.in);
        for(int i = 0; i<5; i++)
        {
            System.out.println("Enter a name:");
            arr[i] = kb.nextLine();
            System.out.println("Enter an ID:");
            arr1[i] = bc.nextInt();
        }}
}

