第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

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

sum++為什么不行

sum++為什么不行

半盞香茗 2016-02-04 18:13:44
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};??????? hello.method(scores);??????? System.out.println("考試成績的前三名為:");??????? ??????? ??????? ??????? ??? }??? ??? //定義方法完成成績排序并輸出前三名的功能??? public void method(int[] scores){??????? Arrays.sort(scores);??????? int sum=0;??????? for(int i=scores.length;i>=0;i--){??????????? if(scores[i]<0||scores[i]>100);{??????????????? continue;??????????? }??????????? sum++;??????????? if(sum>3){??????????????? break;??????????? }??????????????? System.out.println(scores[i]);??????????? ??????? }??? }??? ??? ??? ??? ??? ??? ??? ??? ??? }
查看完整描述

4 回答

已采納
?
IMOOCER_Vi

TA貢獻7條經(jīng)驗 獲得超4個贊

public?void?method(int[]?scores){
????????Arrays.sort(scores);
????????int?sum=0;
????????for(int?i=scores.length-1;i>=0;i--){
????????????if(scores[i]>100){
????????????????continue;
????????????}
????????????sum++;
????????????if(sum>3){
????????????????break;
????????????}
????????????????System.out.println(scores[i]);
????????????
????????}
	}

朋友,你的代碼各種小問題,首先是你在if語句括號后面加了分號,導致if語句判斷完成以后啥都沒干就結束了,所以每次循環(huán)直接執(zhí)行花括號里的continue,然后循環(huán)就結束了,sum++開始,后面的代碼都不能執(zhí)行。其次,你的for循環(huán)里面,i是不能等于scores.length的,否則數(shù)組下標越界。寫代碼的時候要細心哦

查看完整回答
2 反對 回復 2016-02-04
?
qq_灰太狼_27

TA貢獻7條經(jīng)驗 獲得超1個贊

public static void main(String[] args) {

? int[] scores={89,-23,64,91,119,52,73};

? System.out.println("考試成績的前三名為:");

? method1(scores);

}

//定義方法完成成績排序并輸出前三名的功能

? ? public static void method1(int[] scores){

? ? ? ? Arrays.sort(scores);

? ? ? ? int sum=0;

? ? ? ? for(int i=scores.length-1;i>=0;i--){

? ? ? ? ? ? if(scores[i]<0||scores[i]>100){

? ? ? ? ? ? ? ? continue;

? ? ? ? ? ? }

? ? ? ? ? ? sum++;

? ? ? ? ? ? if(sum>3){

? ? ? ? ? ? ? ? break;

? ? ? ? ? ? }

? ? ? ? ? ? ? ? System.out.println(scores[i]);

? ? ? ? ? ??

? ? ? ? }

? ? }


查看完整回答
反對 回復 2016-02-19
?
童年像是一場夢

TA貢獻2條經(jīng)驗 獲得超0個贊

package?test;

import?java.util.Arrays;

public?class?HelloWorld?{

		public??void?method(int[]?scores){
			?Arrays.sort(scores);
		????????int?sum=0;
		????????for(int?i=scores.length-1;i>=0;i--){//這個地方改為i=scores.length-1
		????????????if(scores[i]<0||scores[i]>100){//去掉“;”
		????????????????continue;
		????????????}
		????????????sum++;
		????????????if(sum>3){
		????????????????break;
		????????????}
		????????????????System.out.println(scores[i]);
		????????}
		}
	
		public?static?void?main(String[]?args)?{
			HelloWorld?hello=new?HelloWorld();
	????????int[]?scores={89,-23,64,91,119,52,73};
	????????
	????????System.out.println("考試成績的前三名為:");//調(diào)換下?lián)Q下順序
	????????hello.method(scores);
			
		}
}


查看完整回答
反對 回復 2016-02-04
?
童年像是一場夢

TA貢獻2條經(jīng)驗 獲得超0個贊

我覺得你這個代碼有點問題,應該是?for(int i=scores.length-1;.........

而不是score.length;

查看完整回答
反對 回復 2016-02-04
  • 4 回答
  • 0 關注
  • 1980 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網(wǎng)微信公眾號