I'm getting an unknown number of inputs in an array initially using hasNext()
and the getting another set of inputs but getting NoSuchElementException
.
Code snippet:
public class Hello {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int[] array = new int[100];
int input = 0;
while (sc.hasNext()) {
array[input++] = sc.nextInt();
}
int k = sc.nextInt();
int[] newArray = new int[100];
int j = 0;
for (int h = 0; h < k; h++)
newArray[j++] = sc.nextInt();
}
}