当前位置: 代码迷 >> Java相关 >> 数组问题,请教,大家帮忙
  详细解决方案

数组问题,请教,大家帮忙

热度:414   发布时间:2004-12-09 19:25:00.0
数组问题,请教,大家帮忙

import java.io.* ; public class ExamResult1 { public ExamResult1() { } public static void main(String args[]) { int total = 0 ; int average = 0 ; int stuResult[] = new int[31] ; int stuNumber[] = new int[31] ; String stuName[] = {"","jason" ,"kitty" ,"Ken","San","King", "David","Jerry","Heary","Abs","Coll", "LI","Zhang","Kiki","KAKA","COCO", "Paul","mC","Wade","Nice","Fore", "Opio","Kiss","Kirt","Kurt","Coke", "Frant","OL","eYE","Joe","KK"} ; System.out.println("NAME\t学号\t成绩") ; for (int count = 1 ; count <= 31 ; count++) { stuResult[count] = 1 + (int)(Math.random() * 100 ) ; stuNumber[count] = count ; System.out.println(stuName[count] + "\t" + stuNumber[count] + "\t" + stuResult[count]) ; total += stuResult[count] ; } average = total/30 ; System.out.print("总成绩为" + total); System.out.print("平均成绩为" + average); } }

可以打印出来成绩,学号和姓名,但是打印不出总成绩和平均成绩 。


----------------解决方案--------------------------------------------------------
runtime ArrayIndexOutOfBoundsException,count = 31的时候抛出,自然之后的不会运行了,count&lt;=30 或者count&lt;31

----------------解决方案--------------------------------------------------------
count &lt;= 31 是不是应该为count&lt;31!!!!!!!!!!1
----------------解决方案--------------------------------------------------------
  相关解决方案