Why last element of input is missing in Scanner?

Viewed 959

I use IntelliJ and I have a problem with a Scanner. Last element from the input is missing in the output. Any ideas?

Input: 1, 2, 3
Output: 1, 2

public static void main(String[] args) {
    Scanner sc = new Scanner(System.in).useDelimiter(", ");
    while (sc.hasNext()) {
        System.out.print(sc.nextInt());
    }
}
1 Answers
Related