为什么是Exception in thread "main" java.util.NoSuchElementException,怎么办 20
下面是我的代码publicclassExercise07_01{privatestaticjava.util.Scannerinput;privatestaticjava...
下面是我的代码
public class Exercise07_01 {
private static java.util.Scanner input;
private static java.util.Scanner put;
public static void main(String[] args) {
input = new java.util.Scanner(System.in);
System.out.print("Enter the number of students: " );
int number = input.nextInt();
int[] score = new int[number];
put = new java.util.Scanner(System.in);
System.out.print("Enter " + score.length + " scores: ");
for (int i = 0;i < score.length;i++){
score[i] = put.nextInt();
}
int max = score[0];
for (int i = 1;i < score.length;i++)
if (score[i] > max)
max = score[i];
for (int i = 0;i < score.length;i++){
if (score[i] >= max - 10)
System.out.println("A");
else if (score[i] >= max - 20)
System.out.println("B");
else if (score[i] >= max - 30)
System.out.println("C");
else if (score[i] >= max - 40)
System.out.println("D");
else
System.out.println("F");
}
}
}
它是这么显示的
Enter the number of students: 4
Enter 4 scores: Exception in thread "main" java.util.NoSuchElementException
at java.util.Scanner.throwFor(Scanner.java:863)
at java.util.Scanner.next(Scanner.java:1489)
at java.util.Scanner.nextInt(Scanner.java:2140)
at java.util.Scanner.nextInt(Scanner.java:2096)
at Exercise07_01.main(Exercise07_01.java:22) 展开
public class Exercise07_01 {
private static java.util.Scanner input;
private static java.util.Scanner put;
public static void main(String[] args) {
input = new java.util.Scanner(System.in);
System.out.print("Enter the number of students: " );
int number = input.nextInt();
int[] score = new int[number];
put = new java.util.Scanner(System.in);
System.out.print("Enter " + score.length + " scores: ");
for (int i = 0;i < score.length;i++){
score[i] = put.nextInt();
}
int max = score[0];
for (int i = 1;i < score.length;i++)
if (score[i] > max)
max = score[i];
for (int i = 0;i < score.length;i++){
if (score[i] >= max - 10)
System.out.println("A");
else if (score[i] >= max - 20)
System.out.println("B");
else if (score[i] >= max - 30)
System.out.println("C");
else if (score[i] >= max - 40)
System.out.println("D");
else
System.out.println("F");
}
}
}
它是这么显示的
Enter the number of students: 4
Enter 4 scores: Exception in thread "main" java.util.NoSuchElementException
at java.util.Scanner.throwFor(Scanner.java:863)
at java.util.Scanner.next(Scanner.java:1489)
at java.util.Scanner.nextInt(Scanner.java:2140)
at java.util.Scanner.nextInt(Scanner.java:2096)
at Exercise07_01.main(Exercise07_01.java:22) 展开
2个回答
2015-04-10
展开全部
应该是 java.util.Scanner这个方法不存在,检查一下,这里应该不是一个方法,而是一个类名吧。
追问
我在eclipse里面运行是正常的,放到教学网站上去就不对了
追答
应该你是开发环境和网站环境的JDK版本不一样吧。或者网站上少了什么JAR包
你执行System.out.println(java.util.Scanner.getClass().getProtectionDomain())
看看这个类在哪个包里。如果显示不是jar包路径和名称,那就是JDK本身的问题。
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询