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

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

我個(gè)人覺得這題對我來講還是有一定難度,如果不借用排序,我只能做到排出前兩名,有能夠排出前三名的大佬歡迎留言!


import java.util.Arrays;

public class HelloWorld {

? ??

? ? //完成 main 方法

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

? ? ? ??

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

? ? ? ??

? ? ? ? HelloWorld hello=new HelloWorld();

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

? ? ? ? hello.showThree(scores);

? ? ? ??

? ? }

? ??

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

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

? ? ? ? for(int i=0;i<1;i++){

? ? ? ? ? ? int max=scores[0],max2=scores[1],max3=scores[2];

? ? ? ? ? ? for(int j=0;j<scores.length;j++){

? ? ? ? ? ? ? ? if(max<scores[j]){

? ? ? ? ? ? ? ? ? ? max2=max;

? ? ? ? ? ? ? ? ? ? max=scores[j];

? ? ? ? ? ? ? ? }

? ? ? ? ? ? }

? ? ? ? ? ? System.out.println(max);

? ? ? ? ? ? ?System.out.println(max2);

? ? ? ? ? ? ?System.out.println(max3);

? ? ? ? }

? ? }

? ??

}


正在回答

3 回答

public class HelloWorld {

? ? //完成 main 方法

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

? ? ? ? HelloWorld hello=new HelloWorld();

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

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

? ? ? ? hello.showTop3(scores);

? ? ? ??

? ? }? ??

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

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

? ? ? ? int temp,count=0;

? ? ? ? for(int i=0;i<scores.length-1;i++){? //類似冒泡排序

? ? ? ? for(int j=i+1;j<scores.length;j++){

? ? ? ? if(scores[i]<scores[j]){

? ? ? ? temp=scores[i];

? ? ? ? scores[i]=scores[j];

? ? ? ? scores[j]=temp;

? ? ? ? }

? ? ? ? }

? ? ? ? }

? ? ? ? for(int i=0;i<scores.length;i++){

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

? ? ? ? {

? ? ? ? continue;

? ? ? ? }

? ? ? ? count++;

? ? ? ? if(count<=3){

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

? ? ? ? }

? ? ? ?

? ? ? ? }

? ? }

??

}


0 回復(fù) 有任何疑惑可以回復(fù)我~
public?static??void?showThree(int[]?arrays){
????int?temp?=?0;
????for?(int?i?=?0;?i?<?arrays.length?-?1;?i++)?{
????????for?(int?j?=?1;?j?<?arrays.length?-?i;?j++)?{
????????????if?(arrays[j]?<?arrays[j?-?1])?{
????????????????temp?=?arrays[j];
????????????????arrays[j]?=?arrays[j?-?1];
????????????????arrays[j?-?1]?=?temp;
????????????}
????????}
????}
????for?(int?i?=?arrays.length-1;?i?>=?arrays.length-3?;?i--)?{
????????System.out.println(arrays[i]);
????}
}


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

http://idcbgp.cn/qadetail/330593,昨晚自己利用冒泡排序重新思考了一下,大家可以看一下。

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

舉報(bào)

0/150
提交
取消

我個(gè)人覺得這題對我來講還是有一定難度,如果不借用排序,我只能做到排出前兩名,有能夠排出前三名的大佬歡迎留言!

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

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

幫助反饋 APP下載

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

公眾號

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