for ( int count = 1; count <= 31 ; count++ )数组越界了把count <= 31 改为 count < stuResult.length

解决方案 »

  1.   

    for ( int count = 1; count <= 31 ; count++ )
    这一句有问题,
    你把它改为for ( int count = 1; count <= 30 ; count++ )即可!此为数组溢出问题,在JAVA,C,C++等大多数语言中,
    数组下标皆从0算起。
    如 int [] intArray = new int{31];
    intArray数组有31个元素,从 intArray[0]到intArray[30].你这种问题应该用OOP做!
    定义一个Student 类,这样才叫JAVA程序!
      

  2.   

    应该是for ( int count = 0; count <= 30 ; count++ )或者for ( int count = 0; count <= stuResult.length ; count++ )
    你也不把错误贴出来~
    运行期错误有很多种的!!
      

  3.   

    int stuNumber[] = new int[31] ;java中数组下标是从0开始的
    所以stuNumber的下标范围是0-30所以
     for ( int count = 1; count <= 31 ; count++ )
    i=31时就越界了可以这样;int stuResult[] = new int[31] ;
    int stuNumber[] = new int[31] ;
    改成
    int stuResult[] = new int[32] ;
    int stuNumber[] = new int[32] ;或者
     for ( int count = 1; count <= 31 ; count++ )
    改成
     for ( int count = 0; count < 31 ; count++ )
      

  4.   

    hillMover(老根) 怎么同一时间发,你在我前面阿??? 1秒都不差应该从0开始,你都说数组下标皆从0算起,循环粒还是count=1
      

  5.   

    febchen() 或者
     for ( int count = 1; count <= 31 ; count++ )这样,第一个数据不就丢了??
      

  6.   

    越界。改了一下。jdk1。5下通过。
    import javax.swing.* ;
    import java.io.* ;public class ExamResult {
       public static void main ( String args[] )
         {
           int stuResult[] = new int[31] ;
           int stuNumber[] = new int[31] ;
           String inputName ;
           String output = "" ;
           int passes = 0 ,
               failures = 0 ,
               students = 0 ,
               total = 0 ,
               average = 0 ;
           output = "学号\t" + "成绩" ;
           JTextArea outputArea = new JTextArea() ;
           JScrollPane scrollArea = new JScrollPane( outputArea ) ;
           for ( int count = 1; count <= 30 ; count++ )
            {         stuResult[count] = 1 + (int)(Math.random()*100) ;
             stuNumber[count] = count ;         output += "\n"  + stuNumber[count] + "\t" + stuResult[count] ;         if ( stuResult[count] >= 60 )
               passes++ ;
             else
               {failures++ ;}         students++ ;
             total = total + stuResult[count] ;
            }       average = total / students ;       output += "\n 通过: " + passes + " \n不通过: " + failures + " \n总成绩:"
                     + total + " \n平均成绩 " + average + " \n总人数 " + students ;
           if ( passes > 20 )
           output = output + " \nCOOL!通过率很高啊! " ;
           else
             output = output + " \n成绩太差了! " ;
           outputArea.setText(output);
           JOptionPane.showMessageDialog ( null ,scrollArea ,"最后结果" ,
                                          JOptionPane.INFORMATION_MESSAGE ) ;
           System.exit ( 0 ) ;
          }
        }
      

  7.   

    to: yellowwee(端木柒)只要下标0里不放数据,另外坚持从1开始,就不会丢数据了,只是浪费一个空间而已