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

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

求助 沒有結(jié)果

求助 沒有結(jié)果

慕設(shè)計6419336 2016-11-07 19:52:18
package part1;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();? ? hello.friend(scores);? ? ? ??? ? ? ??? ? ? ??? ? }? ??? ? //定義方法完成成績排 scores){? ? public void friend(int[]scores){? ? ? ? int[] score=new int[10]; for(int i=0;i<scores.length;i++)? ? {? ? ? ? if(scores[i]>0&&scores[i]<=100){? ? ? ? ? ?for(int j=0;j<scores.length;j++)? ? ? ?score[j]=scores[i];}? ? }? ? ?Arrays.sort(score); ? ??? ? System.out.println("成績的前三名:");? ? for(int j=score.length;j>score.length-3;j--)? ? {? ? System.out.println(score[j]);? ? }}
查看完整描述

2 回答

?
每天一點學(xué)

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

你可以先排序,排序是從小到大的,所以你從最后一個開始遍歷,把不符合條件的continue,打印出三個就好了,也就是循環(huán)三次。這樣計較簡單

查看完整回答
2 反對 回復(fù) 2016-11-08
?
每天一點學(xué)

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

import java.util.Arrays;

public class All {

/*

*1、 考試成績已保存在數(shù)組 scores 中,數(shù)組元素依次為 89 , -23 , 64 , 91 , 119 , 52 , 73


*2、 要求通過自定義方法來實現(xiàn)成績排名并輸出操作,將成績數(shù)組作為參數(shù)傳入


*3、 要求判斷成績的有效性( 0—100 ),如果成績無效,則忽略此成績

*/ ? ?

? ? //完成 main 方法

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

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

? ? All outscores=new All();

? ? outscores.three(scores);

? ? } ??

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

public void three(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;

}

if(count<=3) {

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

count++;

}

}

}

}

? ?

? ??

? ??

? ??


查看完整回答
1 反對 回復(fù) 2016-11-08
?
慕粉void

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

int?j?=?score.length;?//?數(shù)組下標越界了

參考代碼

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();
????hello.getScores(scores);
??}

??//?定義方法完成成績排序并輸出前三名的功能
??public?void?getScores(int[]?scores)?{
????Arrays.sort(scores);
????System.out.println("考試成績的前三名為:");
????int?count?=?0;
????for?(int?i?=?scores.length?-?1;?i?>=?0;?i--)?{
??????if?(scores[i]?<?0?||?scores[i]?>?100)?{
????????continue;
??????}?else?{
????????while?(count?<?3)?{
??????????count++;
??????????System.out.println(scores[i]);
??????????break;
????????}
??????}

????}
??}

}


查看完整回答
1 反對 回復(fù) 2016-11-08
?
菜芽2

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

給你兩種思路,一是先用循環(huán)把數(shù)組一中大于0小于100的數(shù)賦值到數(shù)組二,再對數(shù)組二進行冒泡排序,然后再輸出。這樣感覺太麻煩了。還有就是直接對數(shù)組一進行冒泡排序,然后輸出的時候判斷一下,小于100才輸出,定義一個int類型的變量計數(shù),輸出一次+1,等于3了就跳出循環(huán)就好了,這樣簡單很多
查看完整回答
1 反對 回復(fù) 2016-11-07
?
菜芽2

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

你這樣寫,第二個循環(huán)每一次都把score數(shù)組全部都賦值成同一個數(shù)了啊,而且也沒做排序
查看完整回答
1 反對 回復(fù) 2016-11-07
  • 2 回答
  • 0 關(guān)注
  • 1316 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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