供大家參考
import java.util.Arrays;
public class HelloWorld {
? ? public static void main(String[] args) {
? ? ? ? int[] scores={89,-23,64,91,119,52,73};
? ? ? ? HelloWorld h=new HelloWorld();
?System.out.println((Arrays.toString(h.shu(scores))));
? ? }
? ? public int[] shu(int[] aa)
? ? {
? ? ? ? int[] ee=new int[3];//定義新數(shù)組用來存放最大的三個(gè)成績(jī)
? ? ? ? int c=0;
? ? ? ? Arrays.sort(aa);//排序
///// for遍歷數(shù)組///////
? ? ? ? ?for(int i=aa.length-1;i>=0;i--)
? ? ? ? ?{
? ? ? ? ? ? ?if(c<3){
? ? ? ? ? ? ?if(aa[i]>0&&aa[i]<100)?{
? ? ? ? ? ? ? ee[c]=aa[i]; ??
? ? ? ? ? ? ? ? ?c++;? }
? ? ? ? ? ? ?}
? ?}
? ? ? ? ?return ee;
? }
? ??
? ??
? ??
? ??
? ??
? ??
? ??
? ??
}
2018-10-12
看看我的。
2018-09-25
import java.util.Arrays;
public class HelloWorld {
? ??
? ? //完成 main 方法
? ? public static void main(String[] args) {
? ? ? ? HelloWorld hello=new HelloWorld();
? ? ? ? int []scores={89,-23,64,91,119,52,73};
? ? ? ? hello.score(scores);
? ? }
? ??
? ? //定義方法完成成績(jī)排序并輸出前三名的功能
? ? public void score(int [] scores)
? ? {
? ? ? ? Arrays.sort(scores);
? ? ? ? int num = 0;
? ? ? ? for(int i = scores.length-1;i>=0&&num<3;i--)
? ? ? ? {
? ? ? ? ? ? if(scores[i]<0||scores[i]>100)
? ? ? ? ? ? ? ? continue;
? ? ? ? ? ? num++;
? ? ? ? ? ? System.out.println(scores[i]);
? ? ? ? }
? ? }
}
這個(gè)會(huì)簡(jiǎn)單點(diǎn)