Java 构造函数扫描程序(InputStream)未定义
我已经导入了java.util.*但IDE无法识别扫描仪。如果我将其更改为import java.util.Scanner;很好。但是我需要在java.util.*上使用它,因为catch异常是java.util的一部分。顺便说一下,这段代码来自教科书Java 构造函数扫描程序(InputStream)未定义,java,java.util.scanner,Java,Java.util.scanner,我已经导入了java.util.*但IDE无法识别扫描仪。如果我将其更改为import java.util.Scanner;很好。但是我需要在java.util.*上使用它,因为catch异常是java.util的一部分。顺便说一下,这段代码来自教科书 编辑:我正在使用Eclipse import java.util.*; public class GetInteger { static Scanner sc = new Scanner(System.in); public
编辑:我正在使用Eclipse
import java.util.*;
public class GetInteger {
static Scanner sc = new Scanner(System.in);
public static void main(String[] args) {
System.out.print("Enter an integer: ");
int i = GetAnInteger();
System.out.println("You entered " + i);
}
public static int GetAnInteger() {
while(true) {
try {
return sc.nextInt();
}
catch (InputMismatchException e) {
sc.next();
System.out.println("That's not an integer. Try again: ");
}
}
}
}
这是哪一个IDE?可能是Netbeans,因为我在Eclipse中尝试过,它可以工作。无论如何,我不建议使用
import java.util.*代码>但只导入真正要使用的类。使用不同的ide,如intellij。清除ide的缓存。i、 e Netbeans()我正在使用Eclipse