问答详情
源自:7-1 编程练习

我自己做的没有报错,但是越界怎么解决

package wvw;
import java.util.Arrays;

public class HelloWord {

 public static void main(String[] args) {
  int scores[] = {89,-23,64,91,119,52,73};
  HelloWord A = new HelloWord();
  System.out.println("成绩前三有:");
  A.top3(scores);
  
  /*Arrays.sort(scores);
  for(int i = scores.length-1;i >=0;i--) {
     System.out.print(scores[i] + " ");*/
   

 }
  
  
  public void top3(int []scores) {
   Arrays.sort(scores);
   int mun = 0;
   for(int i = scores.length-1;i >=0;i++) {
    if(0 <= scores[i] && scores[i] <= 100) {
     System.out.print(scores + " ");
    }else{
     continue;
    }
    
    while(mun < 3) {
     System.out.print(scores[i]);
     mun++;
    }
   }
   
  }   


 
  
 
 
}


提问者:qq_慕瓜0112281 2020-01-01 23:40

个回答

  • weixin_慕娘0598973
    2020-01-07 11:51:19
    已采纳

    for循环里面的循环变量i应该是递减,你写成i++了

  • qq_慕瓜0112281
    2020-01-09 22:29:17

    失误哈哈