这是我的 for 循环...jGRASP 说我的 for 循环行开始出现问题,我看不到问题,需要一些帮助来修复我的代码...
公共(public)类DirectoryLookup { public static void main(String[] args) 抛出 IOException {
if (args.length == 0) {
System.out.println("Please supply data file");
System.exit(0);
}
else {
System.out.println("Database server is Ready for Number Lookups!");
}
File inputDataFile = new File(args[0]);
Scanner inputFile = new Scanner(inputDataFile)
Scanner input = new Scanner(input.in);
int n = inputFile.nextInt();
int list[] = new int[n];
found = false;
while (Scanner.hasNext()); {
System.out.println("Enter number to check value");
int x = input.nextInt();
for (i = 0, i < n, i++);
if (x == list(i)); {
found = true; break
System.out.println("x is in the list");
else {
System.out.println("x is not in the list");
}
}
最佳答案
while
条件、for
循环声明和 if
条件后面有分号。需要将它们删除,否则 Java 会将分号本身视为正文。
您的 break
语句中缺少分号,并且 else
之前缺少结束大括号 }
。
关于java - jGRASP 说我的 for 循环不正确,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19392275/