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

為了賬號安全,請及時綁定郵箱和手機立即綁定

第三位有兩個的話?

有同學(xué)考慮過第三位有兩個分數(shù)相同的情況嗎?這種情況該怎么寫呢?

正在回答

2 回答

import java.util.Arrays;

public class HelloWorld {

? ??

? ? //完成 main 方法

? ? public static void main(String[] args){

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

HelloWorld hello=new HelloWorld();

hello.chenJi(scores);

}

? ??

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

? ? public void chenJi(int [] cores){

int a=0;

int b=0;

Arrays.sort(cores);

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

for(int i=cores.length-1;i>=0;i--){//排除大于100和小于0的數(shù).

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

continue;

}else if((b<3)||(cores[i+1]==cores[i])){//判斷是否滿足前三名,如果第三名有兩個相同的成績,就把相同的成績也打印出來.如果沒有相同成績就只打印3個成績.

a=cores[i];

b++;

System.out.println(a);

}else{

break;

}

}

}

? ?

0 回復(fù) 有任何疑惑可以回復(fù)我~
#1

蒼蠅拍拍 提問者

非常感謝!
2017-05-28 回復(fù) 有任何疑惑可以回復(fù)我~
public?class?helloWorld?{
	public?static?void?main(String[]?args)?{
		//?定義一個整型數(shù)組,保存成績信息
		int[]?scores?=?{?89,?89,?64,?91,?73,?89,?73};
		helloWorld?hello?=?new?helloWorld();
		hello.thirdCore(scores);
	}
	public?void?thirdCore(int[]?scores){
		Arrays.sort(scores);
		int?count?=?1;
		for(int?i=(scores.length-1);i>=0;i--){
			if(scores[i]<0?||?scores[i]>100){
				continue;
			}else{
				if(scores[i]?==?scores[i-1]){
					System.out.print("索引為"+i+":"+scores[i]);
				}else{
					count++;
					System.out.println("索引為"+i+":"+scores[i]);
				}
				if(count>3){
					break;
				}
			}
		}
	}
}


0 回復(fù) 有任何疑惑可以回復(fù)我~
#1

蒼蠅拍拍 提問者

同學(xué)你的代碼也很棒,我還以為可以兩個都采納。。抱歉了,謝謝你!
2017-05-28 回復(fù) 有任何疑惑可以回復(fù)我~

舉報

0/150
提交
取消
Java入門第一季(IDEA工具)升級版
  • 參與學(xué)習(xí)       1167325    人
  • 解答問題       18530    個

0基礎(chǔ)萌新入門第一課,從Java環(huán)境搭建、工具使用、基礎(chǔ)語法開始

進入課程

第三位有兩個的話?

我要回答 關(guān)注問題
微信客服

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

幫助反饋 APP下載

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

公眾號

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