求大神指教。int num=0;啥意思啊,為啥加這個,num++又是啥啊
import java.util.Arrays;
public class HelloWorld {
? ? public static void main(String[] args) {
? ? ? ? int [] scores={89 , -23 , 64 , 91 , 119 , 52 , 73};
? ? ? ? HelloWorld hello = new HelloWorld();? ??
? ? ? ? ? ? hello.a(scores);
? ??
? ? }
? ? //定義方法完成成績排序并輸出前三名的功能
? ? public void a(int[] scores){
? ? ? ??
? ? ? ? Arrays.sort(scores);
? ? ? ? int num =0;
? ? ? ? for (int i = scores.length-1;i >= 0; i-- ){
? ? ? ? ? ? if(scores[i]<0||scores[i]>100){
? ? ? ? ? ? ? ? continue;}
? ? ? ? ? ? num++;
? ? ? ? ? ?if(num>3){
? ? ? ? ? ? ? ?break;
? ? ? ? ? ? }System.out.println(scores[i]);
? ? ? ? ? ? }
? ? ? ? ? ??
? ? ? ? }
? ? }
? ??
2019-06-03
這里的num做的是循環(huán)體,目的是排出前三名,走的循環(huán)過程是i = scores.length-1時,num = 0,依次向下,當(dāng)num大于3時跳出循環(huán),得到你通過Arrays.sort()排序后得到的最大的三個成績