Here is the problem. You have this...
System.out.println("How many numbers will be entered?");
n = sc.nextInt();
...which is later followed by this...
input = sc. nextLine();
Long story short, nextLine()
does not play well with the other next***()
methods of the scanner. You can read here for more info - https://stackoverflow.com/a/13102066/10118965
The easiest way to solve your problem would be to do this
System.out.println("How many numbers will be entered?");
n = sc.nextInt();
sc.nextLine();
That's probably the least painful way to solve this. But in the future, you can avoid this problem entirely if you only use nextLine()
. Those convenience methods are nice, but as you see, they can cause you problems if you don't know their particular nuances.