這個里面這個i代表什么?
import java.util.Arrays
public class HelloWorld {
? ??
? ? //完成 main 方法
? ? public static void main(String[] args) {
? ? ? ? int []scores={89,-23,64,91,119,52,73}//定義數組scores中有這些數字
? ? ? ? System.out.println("本次考試前三的是")
? ? ? ? HelloWorld hello=new HelloWorld();//新建對象hello
? ? ? ? hello.big3(scores);//調用big3方法
? ? }
? ??
? ? //定義方法完成成績排序并輸出前三名的功能?
? ? public void big3(int [] scores){//名為big3的方法
? ? ? ? ?Arrays.sort(scores);//排序
? ? ? ? ?int num=0//定義一個名為num的變量 保存有效成績的數量
? ? ? ? ?//這個for判斷排序長度,排序長度為3 從后往前遍歷,即倒序遍歷每一個元素
? ? ? ? ?for(int i = scores.length-1;i>=0&&num<3;i--)//scores.length排序長度
? ? ? ? {
? ? ? ? ? ? if(scores[i]<0||scores[i]>100)//i是排名長度 判斷成績的有效性
? ? ? ? ? ? ? ? continue;//如果成績小于 0 或大于 100 ,則使用 continue 忽略此成績
? ? ? ? ? ? num++;//如果在范圍內num+1
? ? ? ? ? ? //i代表成績的變量
? ? ? ? ? ? //scores數組名
? ? ? ? ? ?if(num>3){
? ? ? ? ? ? ? ?brack;
? ? ? ? ? ?}
? ? ? ? ? ? System.out.println(scores[i]);
? ? ? ? }
? ? }
2016-10-30
i代表數組scores中元素的個數(從0開始)
2016-10-30
這里面只有scores[i]中有i,這個i代表數組中第i+1個元素。