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

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

覺得給出的額參考答案有點問題啊

我怎么感覺這個題目給出的答案有點問題???你們有問題嗎?伙計們

正在回答

3 回答

import?java.util.Arrays;

public?class?HelloWorld?{
????public?static?void?main(String[]?args)?{
????????HelloWorld?hello?=?new?HelloWorld();
????????int[]?scores?=?{9,-23,64,91,119,52,73};
????????//接收返回的前三名成績
????????int[]?top3?=?hello.getSorted(scores);
????????//輸出前三名
????????System.out.println("前三名的成績是:\n"?+?Arrays.toString(top3));

????}
????public?int[]?getSorted(int[]?scores){
????????//定義數(shù)組用以存儲前三名成績
????????int[]?top?=?new?int[3];
????????
????????System.out.println("原始成績是:\n"?+?Arrays.toString(scores));
????????
????????//排序
????????Arrays.sort(scores);
????????
????????System.out.println("排序后的成績是:\n"?+?Arrays.toString(scores));
????????//原始成績數(shù)組編號,為保證下一個循環(huán)繼續(xù)往后跳,所以這里提前定義,且為了保證從最大值讀取,所以這里初始值定義為數(shù)組長度-1
????????int?i=scores.length?-1;
????????
????????//j定義為為前三名數(shù)組編號
????????for(int?j=0;j<3;j++){
????????????while(i>=0){
????????????????//如果成績不在0-100內(nèi),跳至下一個(i--),不做賦值
????????????????if(scores[i]<0?||?scores[i]>?100){
????????????????????i--;
????????????????????continue;
????????????????}
????????????????//成績在0-100內(nèi),賦值給top數(shù)組,并跳出循環(huán),并保證下一個循環(huán)內(nèi)成績繼續(xù)往后查詢(i--)
????????????????top[j]?=?scores[i];
????????????????i--;
????????????????break;
????????????}
????????}
????????return?top;
????}
}


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

我自己想了想,分享下:

import java.util.Arrays;


public class Homework1 {

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

????????Homework1 hw=new Homework1();

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

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

????????????hw.showTop3(scores);

????}

????????????public void showTop3(int[] scores){

????????????????????int count=0;

????????????????Arrays.sort(scores);

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

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

????????????????????????continue;

?????????????????}else{

????????????????????????count++;

????????????????????????}

????????????????if(count>3){

????????????????????break;

?????????????????}

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

????????}

????}

}



2 回復(fù) 有任何疑惑可以回復(fù)我~

例如?

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

舉報

0/150
提交
取消

覺得給出的額參考答案有點問題啊

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

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

幫助反饋 APP下載

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

公眾號

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