qq_天不下雨_0
2015-12-27 19:05
求怎么写这道题的带返回值的代码?谢谢
package come.imooc;
import java.util.Arrays;
public class Test2 {
public static void main(String[] args) {
int[] scores = {89 , -23 , 64 , 91 , 119 , 52 , 73};
Test2 helloWorld = new Test2();
System.out.println("考试成绩的前三名为:");
int[] top3Nums = Test2.big3(scores);
for(int i=0;i<top3Nums.length;i++){ // 循环输出返回的值。
System.out.println(top3Nums[i]);
}
}
//定义方法完成成绩排序并输出前三名的功能
public static int[] big3(int [] scores)
{
Arrays.sort(scores);
int num = 0;
int[] top3Nums = new int[3]; // 定义将要返回的数组。
for(int i =scores.length-1;i>=0;i--)
{
if(scores[i]<0||scores[i]>100)
continue;
//System.out.println(scores[i]); // 这里就不要输出了。
top3Nums[num] = scores[i];
num ++;
if(num==3)
break;
}
return top3Nums;
}
}
什么题?
Java入门第一季(IDEA工具)
1168080 学习 · 18753 问题
相似问题
回答 2
回答 4
回答 3
回答 1
回答 4