0

I have a small program to scan an Integer from console, also I would like to use new line character as delimiter.

import java.util.Scanner;

public class TestScanner {

public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in).useDelimiter("\n");
    System.out.println("Enter the int");
    int testInt = scanner.nextInt();
    System.out.println(testInt);
}

}

Intellij runs and exist normal way.. enter image description here

Where as Eclipse produce, java.util.InputMismatchException

In Run mode you can observe an exception, with debug mode, code will run with out any issues enter image description here

Source : jdk1.8.0_161 ( Oracle )

Eclipse : enter image description here

This is strange. Kindly help me to understand how this can be corrected. Thanking you!

jegadeesh
  • 109
  • 2
  • 8

1 Answers1

1

Late but... if you're in Windows you should use "\r\n" instead of just "\n"