亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

為什么這個num一直報錯

為什么這個num一直報錯

ThreeAgain 2017-06-28 17:50:57
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("前三名的成績:");//輸出? ? ? ? HelloWorld ?hello = new ?HelloWorld() ; //建對象? ? ? ? hello.three(scores);//調用方法,傳入數組? ?? ? }? ??? ? //定義方法完成成績排序并輸出前三名的功能? ? ? ?public void three (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]);? ? ? ?}? ? ? ? ? ?}? ? ? ?? ? }? ? ?? ??}
查看完整描述

3 回答

已采納
?
望遠

TA貢獻1017條經驗 獲得超1032個贊

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("前三名的成績:");//輸出
		HelloWorld??hello?=?new??HelloWorld()?;?//建對象
		hello.three(scores);//調用方法,傳入數組

	}

	//定義方法完成成績排序并輸出前三名的功能
	public?void?three?(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;//continue后面的代碼無法得到執行,而報錯。
			}//你應該是想這樣寫,輸出成績前三名,注意花括號的位置
			num++;


			if(num>3){
				break;
			}
			System.out.println(scores[i]);
		}

	}


}


查看完整回答
1 反對 回復 2017-06-28
?
蜂之谷

TA貢獻564條經驗 獲得超863個贊

continue 后不能再寫其它代碼了

查看完整回答
反對 回復 2017-06-28
  • 3 回答
  • 0 關注
  • 1598 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號