Note that when you do int numbers = keyboard.nextInt();
, it reads only the int
value (and skips the \n
which is the enter key you press right after) - See Scanner#nextInt
.
So when you continue reading with keyboard.nextLine()
you receive the \n
.
You can add another keyboard.nextLine()
in order to read the skipped \n
from nextInt()
.
The exception you're getting is because you're trying to use charAt
on \n
.