這樣可以嗎?
import java.util.Arrays;
public class HelloWorld {
? ??
? ? //完成 main 方法
? ? public static void main(String[] args) {
? ? ? ? int[] scores={89,-23 , 64 , 91 , 119 , 52 , 73};
? ? ? ? int imax=3;
? ? ? ? HelloWorld hello=new HelloWorld();
? ? ? ? hello.qiansanming(scores,imax);
? ? ? ? }
? ? ? ??
? ? ? ??
? ? ? ??
? ? }
? ? public int qiansanming(int[] scores,imax){
? ? ? ? //int[] scores;
? ? ? ? Array.sort(scores);
? ? ? ? //int score1;
? ? ? ? //int score2;
? ? ? ? //int scores3;
? ? ? ? int n=0;
? ? ? ? for(int i=scores.length-1;i>=0;i--){
? ? ? ? ? ? if (scores(i)>1&scores(i)<100&n<=imax){
? ? ? ? ? ? ? ? return scores[i];
? ? ? ? ? ? ? ? n++;
? ? ? ? ? ? ? ? }
? ? ? ? ? ? else{
? ? ? ? ? ? ? ? continue;
? ? ? ? ? ? ? ? }
? ? ? ? ? ? }
? ? ? ? ? ? //return scores(i);
? ? ? ? ? ? System.out.println(考試成績的前三名為:scores[i]);
? ? ? ? }
? ? ? ??
? ? }
? ??
? ? //定義方法完成成績排序并輸出前三名的功能
? ??
? ??
? ??
2019-04-22
不行的,首先,java中數組取值應當用中括號;其次,return 語句之后的語句是不會執行的,因此你的方法即使語法沒有問題,也只會返回一個數值。