課程
/后端開發(fā)
/Java
/Java入門第一季(IDEA工具)升級版
2017-03-01
源自:Java入門第一季(IDEA工具)升級版 7-1
正在回答
打印的是數(shù)組的地址,而沒有指定數(shù)組元素
public class HelloWorld {?? ?public static void main(String[] args) {?? ??? ?HelloWorld hello = new HelloWorld();?? ??? ?int[] scores = { 89, -23, 64, 91, 119, 52, 73 };?? ??? ?hello.list(scores);?? ?}?? ?public void list(int []scores) {?? ??? ?Arrays.sort(scores);?? ??? ?int count = 0;?? ??? ?int []topThree = new int [3];?? ??? ?for(int i = scores.length-1;i>=0;i--){?? ??? ??? ?if (scores[i] < 0 || scores[i] >100)?? ??? ??? ??? ?continue;?? ??? ??? ?topThree[count] = scores[i];?? ??? ??? ?count++;?? ??? ??? ?if(count == 3)?? ??? ??? ??? ?break;?? ??? ?}?? ??? ?System.out.println(Arrays.toString(topThree));?? ?}}
試試這個咯
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(Arrays.toString(getArray(scores))); ???}?? ????//定義方法完成成績排序并輸出前三名的功能? ????public?static?int[]?getArray(int[]?array) ????{ ????????Arrays.sort(array); ????????int?count=-1; ????????int[]?newArray=new?int[3]; ????????for(int?i=array.length-1;i>=0;i--) ????????{ ????????????if(array[i]<0||array[i]>100) ????????????{ ????????????????continue; ????????????} ????????????count++; ????????????newArray[count]=array[i]; ????????????if(count==2) ????????????????{ ????????????????????break; ????????????????} ????????} ????????return?newArray; ????}??? }
我不知道寫的好不好,以后再回來改吧
把 count定義到循環(huán)外,不然每次循環(huán)count都重新置0
你沒輸出前三名啊 ??
Object_66
舉報
0基礎萌新入門第一課,從Java環(huán)境搭建、工具使用、基礎語法開始
3 回答第一季8-1我該怎么改才能輸出前三名?
2 回答java 入門第一季 8-1的編程練習
4 回答第一季8-1
1 回答第一季 8-1
1 回答java入門第一季8-1編程練習 while與if
Copyright ? 2025 imooc.com All Rights Reserved | 京ICP備12003892號-11 京公網(wǎng)安備11010802030151號
購課補貼聯(lián)系客服咨詢優(yōu)惠詳情
慕課網(wǎng)APP您的移動學習伙伴
掃描二維碼關注慕課網(wǎng)微信公眾號
2017-03-18
打印的是數(shù)組的地址,而沒有指定數(shù)組元素
2017-03-03
public class HelloWorld {
?? ?public static void main(String[] args) {
?? ??? ?HelloWorld hello = new HelloWorld();
?? ??? ?int[] scores = { 89, -23, 64, 91, 119, 52, 73 };
?? ??? ?hello.list(scores);
?? ?}
?? ?public void list(int []scores) {
?? ??? ?Arrays.sort(scores);
?? ??? ?int count = 0;
?? ??? ?int []topThree = new int [3];
?? ??? ?for(int i = scores.length-1;i>=0;i--){
?? ??? ??? ?if (scores[i] < 0 || scores[i] >100)
?? ??? ??? ??? ?continue;
?? ??? ??? ?topThree[count] = scores[i];
?? ??? ??? ?count++;
?? ??? ??? ?if(count == 3)
?? ??? ??? ??? ?break;
?? ??? ?}
?? ??? ?System.out.println(Arrays.toString(topThree));
?? ?}
}
試試這個咯
2017-03-02
我不知道寫的好不好,以后再回來改吧
2017-03-01
把 count定義到循環(huán)外,不然每次循環(huán)count都重新置0
2017-03-01
你沒輸出前三名啊 ??