package one;import java.util.Arrays;public class one { //完成 main 方法 public static void main(String[] args) { one hello=new one(); int[] scores={89 , -23 , 64 , 91 , 119 , 52 , 73}; int[] three=hello.change(scores); //wrong System.out.println(three); } //定义方法完成成绩排序并输出前三名的功能 public int change(int[] scores){ Arrays.sort(scores); int[] one=new int[3]; for(int i = 0 ; i < 3 ; i++){ if(scores[i] > 0 && scores[i] < 100){ int m=0; one[m]=scores[i]; m++; } return one; //wrong } } }
1 回答
已采纳
慕莱坞9220042
TA贡献377条经验 获得超508个赞
你好,
package one;
import java.util.Arrays;
public class one {
//完成 main 方法
public static void main(String[] args) {
one hello=new one();
int[] scores={89 , -23 , 64 , 91 , 119 , 52 , 73};
int[] three=hello.change(scores); //wrong
for (int i = 0; i < three.length; i++) {
System.out.println(three[i]+",");
}
System.out.println(three);
}
//定义方法完成成绩排序并输出前三名的功能
public int[] change(int[] scores){
Arrays.sort(scores);
int[] one=new int[3];
for(int i = 0 ; i < 3 ; i++){
if(scores[i] > 0 && scores[i] < 100){
int m=0;
one[m]=scores[i];
m++;
}
}
return one; //wrong
}
}试下这个,可以正常运行,具体输出好像有问题,自己查下代码看下哪里不对;
望楼主采纳!
添加回答
举报
0/150
提交
取消
