亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

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

找不到問題,求大神支援

import java.util.Arrays;

public class HelloWorld {

? ??

? ? //完成 main 方法

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

? ? ? ? int [] h={90,98,89,78,68,0};

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

? ? ? ? int []g=hello.getScores(h);

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

? ? ? ? for(int d:g){

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

? ? ? ? }

? ? ? ??

? ? }

? ??

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

? ? public int[] getScores(int[]a){

? ? ? ? int []b=Arrays.sort(a);

? ? ? ? int []c=new int[3];

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

? ? ? ? ? ? if(b[i]<100&&b[i]>0)

? ? ? ? ? ? c[i]=b[i];

? ? ? ? ? ? else

? ? ? ? ? ? c[i]=0;

? ? ? ? }

? ? ? ?return c;?

? ? }

}

http://img1.sycdn.imooc.com//577e43060001144d07570567.jpg

正在回答

2 回答

你根本沒按提示做按。。。

package?com.helloworld;
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.max(scores);??
???}
???
???//定義方法完成成績排序并輸出前三名的功能
???public?void?max(int?scores[]){
???????//nums是用來看是否到了3個
???????int?i,nums=0;
???????//將scores數組升序排序
???????Arrays.sort(scores);
???????//使用?for?循環遍歷數組中的元素,由于要輸出的是前三名成績,所以從后往前遍歷,即倒序遍歷
???????for?(?i?=?scores.length?-?1;?i?>=?0;?i--?)?{?
???????????//如果數字不符合條件,continue跳過循環
???????????if(scores[i]<0||scores[i]>100){
???????????????continue;
???????????}
???????????nums=nums+1;
???????????System.out.println(scores[i]);
???????????if(nums>=3){
???????????????break;
???????????}
???????????}
???????
???????
???}

這是我的方法,希望采納。

0 回復 有任何疑惑可以回復我~
public?class?HelloWorld?{
????
????//完成?main?方法
????public?static?void?main(String[]?args)?{
????????int[]?scores?=?new?int[]{89,-23,64,91,119,52,73};
????????sortArray(scores);
????}
????
????//定義方法完成成績排序并輸出前三名的功能
????
????public?static?void?sortArray(int[]?arr){
????????int?temp?=?0;
????????for(int?i?=?0?;?i<?arr.length;?i++){
???????????if(arr[i]<0?||?arr[i]?>?100?){
????????????????arr[i]?=?0;
????????????}
????????}
????????for(int?i?=?0?;?i?<?arr.length;i++){
????????????for?(int?j?=?i?+?1?;?j?<?arr.length?;?j++){
????????????????if(arr[i]<arr[j]){
????????????????????temp?=?arr[i];
????????????????????arr[i]?=?arr[j];
????????????????????arr[j]?=?temp;
????????????????}
????????????}
????????}
????????for(int?i?=?0?;?i<?arr.length;?i++){
????????????if(i?<?3?)
????????????????System.out.println(arr[i]);
????????}
????}
}

這是我寫的答案,可能有點小麻煩吧,你可以看一下。如果不是因為不知道怎么寫,而是因為不知道你的為什么會出現問題的話,可以私聊我,我幫你解釋一下。

0 回復 有任何疑惑可以回復我~

舉報

0/150
提交
取消

找不到問題,求大神支援

我要回答 關注問題
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號