沒(méi)有運(yùn)行出成績(jī),是哪里出問(wèn)題了。
import java.util.Arrays;//導(dǎo)入java.util.Arrays
public class HelloWorld {
? ??
? ? //完成 main 方法
? ? public static void main(String[] args) {
? ? ? ? int [] scores={89,-23,64,91,119,52,73};//數(shù)組
? ? ? ??
? ? ? ? System.out.println("本次考試的前三名為:");
? ? ? ??
? ? ? ? HelloWorld hello=new HelloWorld();
? ? ? ? hello.show(scores);
? ? ? ??
? ? ? ??
? ? }
? ??
? ? //定義方法完成成績(jī)排序并輸出前三名的功能
? ? public void show(int [] scores){
? ? ? ? Arrays.sort(scores);
? ? ? ? int num=0;
? ? ? ? for(int i=scores.length-1; i>=0;i--){
? ? ? ? ? ? ?if(i>=0 || i<=100){
? ? ? ? ? ? continue;//小于0,大于100,跳出本次循環(huán),進(jìn)行下一次。如果是119,直接忽略。
? ? ? ? }if(num<3){
? ? ? ? ? ? System.out.println(scores[i]);
? ? ? ? ? ? num++;
? ? ? ? }
? ? ? ? else{
? ? ? ??
? ? ? ??
? ? ? ??
? ? ? ? break;
? ? ? ? }
? ? }
? ??
? ??
? ??
? ? }
? ??
? ??
? ??
2020-08-14
2020-07-17
錯(cuò)誤1. if(i>=0 || i<=100)? //大于0,小于100,跳出本次循環(huán),進(jìn)行下一次。
錯(cuò)誤2.System.out.println(scores[i]);應(yīng)該放在for這個(gè)操作內(nèi)容里面,你放到if里面了
錯(cuò)誤3.最后面缺一個(gè)大括號(hào)對(duì)應(yīng)HelloWorld{
2020-07-17
System.out.println(scores[i]);應(yīng)該放在for這個(gè)操作內(nèi)容里面,你放到if里面了