怎么成績(jī)?nèi)?
import java.util.*;
public class HelloWorld {? ?
??? //完成 main 方法
??? public static void main(String[] args) {
??????? int[] scores = {89,-23,64,91,119,52,73};
??????? TopE(scores);
?????? ?
?????? ?
??? }
?? ?
??? //定義方法完成成績(jī)排序并輸出前三名的功能
?? ?
??? public? static void TopE(int[] in) {
??????? int count = 0;
??????? int[] ab = new int[3];
??????? int j = 0;
??????? try{
??????????? for(int i = in.length; i >= 0; i--) {
??????????? if(in[i]>0 && in[i]<100) {
??????????????? ab[j++] = in[i];
??????????????? count++;
??????????? if(count > 3)
??????????????? break;
??????????? }else {continue;}
??????? }
?????????? }catch (Exception e) {}
??????????? System.out.println("考試成績(jī)的前三名為:");
??????? Arrays.sort(ab);
??????? System.out.println(Arrays.toString(ab));
??? }
?? ?
?????? ?
}
2016-06-22
package com.imooc;
import java.util.Arrays;
import java.util.Scanner;
public class HelloWord {
?public static void main(String[] args){
??HelloWord hello=new HelloWord();
??int[] scores={89 , -23 , 64 , 91 , 119 , 52 , 73};
??System.out.println("考試的前三名為:");
??hello.third(scores);
???????
?}
?public void third(int[] scores) {
??// TODO Auto-generated method stub
??Arrays.sort(scores);
??int count=0;
??for(int i=scores.length-1;i>=0;i--){
???if(scores[i]<0||scores[i]>100) continue;
???count++;
???if(count<=3) System.out.println(scores[i]);
??}
?}
}