為什么數組輸入不能放在show方法中?
import java.util.Arrays;
public class HelloWorld {
? ??
? ? //完成 main 方法
? ? public static void main(String[] args) {
? ? ? ? HelloWorld hello = new HelloWorld();
? ? ? ? hello.show(scores);
? ? ? ??
? ? }
? ??
? ? //定義方法完成成績排序并輸出前三名的功能
? ? ? public void show(int[] scores){
? ? ? ? int[] scores = new int[]{89,-23,64,91,119,52,73};
? ? ? ? Arrays.sort(scores);
? ? ? ? int count = 0;
? ? ? ? for(int i = scores.length - 1; i >= 0; i--){
? ? ? ? ? ?
? ? ? ? ?if(scores[i]<0||scores[i]>100){
? ? ? ? ? ? ?continue;
? ? ? ? ?}else{
? ? ? ? ? ? ?count++;
? ? ? ? ?}
? ? ? ? ?if(count>3){
? ? ? ? ? ? ?break;
? ? ? ? ?}
? ? ? ? ?System.out.println(scores[i]);
? ? ? ? ? }
? ? ? ? ??
? ? ? ? ? ? }
? ? ? ? ? ?
? ? ? ? ? ?
? ? ? ? }
? ? ? ??
2017-01-24
你確定這個代碼能編譯?
2017-01-23
建議樓主查看同學代碼中,第一個很不錯呢,思路清晰明了,