不知道為什么運(yùn)行不了
import java.util.Arrays;?
public class HelloWorld {
? ?
? ? //完成 main 方法
? ? public static void main(String[] args) {
? ? ? int[]scores ={89,-23,64,91,119,52,73};
? ? ?
? ? ? System.out.println("輸出成績(jī)前三名");
? ? ? ?HelloWord hello = new HelloWorld();
? ? ? ?hello.showTop3(scores);
? ? ? ??
? ? }
? ??
? ? //定義方法完成成績(jī)排序并輸出前三名的功能
? ? public void showTop3(int[]scores){
? ? ? ? Arrays.sort(scores);
? ? ? ? int nums = 0;
? ? ? ? for(int i=scores.length-1;i>=0;i--){
? ? ? ? ? ? if(scores[i]<0||scores[i]>100){
? ? ? ? ? ? ? ? continue;
? ? ? ? ? ? ? ? ?}nums++;
? ? ? ? ? ? ? ? ?if(nums>3){
? ? ? ? ? ? ? ? ? ? break;
? ? ? ? ? ? ? ? }
? ? ? ? } System.out.println(scores[i]);
? ??
? ? ? ? ??
? ? ? ??
? ? }
? ??
? ??
? ??
? ??
? ??
? ??
? ??
? ??
? ??
}
2018-10-16
2018-10-16
上面代碼是我的,你有兩個(gè)問題,
第一個(gè),你寫的
HelloWord hello = new HelloWorld();
第一個(gè)單詞寫錯(cuò)了,實(shí)際為
第二個(gè)輸出寫在for循環(huán)外面了