我的這個代碼有問題,沒有顯示錯誤,但可以運行
import java.util.Arrays;
public class HelloWorld {
? ??
? ? //完成 main 方法
? ? public static void main(String[] args) {
? ? ? ? HelloWorld hello=new HelloWorld();
? ? ? ? int[] scores={89,-23,64,91,119,52,73};
? ? ? ? System.out.println("前三名的成績?yōu)椋?);
? ? ? ? hello.show(scores);
? ? ? ??
? ? ? ??
? ? ? ??
? ? ? ??
? ? }
? ??
? ? //定義方法完成成績排序并輸出前三名的功能
? ? public void show(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]);
? ? ? ? }
? ? }
? ??
? ??
? ??
2022-03-25
控制下font-style第8章編程挑戰(zhàn)就是一個包含大部分知識點的練習(xí),后續(xù)的課程也會依次推出,敬請關(guān)注。
2018-08-13
最后缺一個}
2018-08-13
自定義Method show() 的第五行,forloop里的第一個if。scores里面有一個119因為這個判斷被跳過了。