不懂為什么這樣。。。。
public void showTop3(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]);
? ? ? ? }
?這里
? for(int i=scores.length-1;i>=0;i--){
? ? ? ? ? ? if(scores[i]<0||scores[i]>100){
? ? ? ? ? ? ? ? continue;
的意義是什么,,,為什么scores.length-1,,,
2016-07-14
數(shù)組的編號是從0開始的也就是說scores[0]是數(shù)組的第一個數(shù)字,如果數(shù)組有3個參數(shù),第3個的編號就是scores[2],scores.length是數(shù)組的長度3,i是數(shù)組的編號,那么循環(huán)到第3個數(shù)的時候,i就應該是2,i=3的話就會循環(huán)到數(shù)組的第4個數(shù)造成越界
2016-07-14
數(shù)組的編號是從0開始的也就是說scores[0]是數(shù)組的第一個數(shù)字,如果數(shù)組有100個參數(shù),第一百個的編號就是scores[99],scores.length是數(shù)組的長度100,i是數(shù)組的編號,那么循環(huán)到第一百個數(shù)的時候,i就應該是99,i=100的話就會循環(huán)到數(shù)組的第101個數(shù)造成越界