課程
/后端開發(fā)
/Java
/Java入門第一季(IDEA工具)升級版
考試成績的前三名為: -23 52 64
2015-03-26
源自:Java入門第一季(IDEA工具)升級版 7-1
正在回答
import?java.util.Arrays; public?class?HelloWorld?{ ????? ????public?static?void?main(String[]?args)?{ ????HelloWorld?hello?=?new?HelloWorld(); ????int[]?scores?={89,-23,64,91,119,52,73}; ????Arrays.sort(scores);???? ????System.out.println("考試成績的前三名為:");???? ????hello.getScores(scores); ????} ???? ????public?void?getScores(int[]?scores){ ????????int?count?=?0; ????????for(int?i=scores.length-1;i>=0;i--){ ????????????if(scores[i]<=100?&&?scores[i]?>=0?&&?count?<?3){ ????????????????System.out.println(scores[i]); ????????????????count?+=?1; ????????????}?????????? ????????} ????} }
為什么樓主要自己定義方法排序呢?有sort方法啊。會簡潔不少。
a=3;
并不是a就是3,而是a指向3
所以
int a,b;
a=a+b;
b=a-b;
a=a-b;
這樣可以交換這兩個數(shù)...
package com.rui.text;public class JavaDemoTest {?? ???? public static void main(String[] args) {?? ??? ?JavaDemoTest hello=new JavaDemoTest();??????? int []scores={89,-23,64,91,119,52,73};?? ???????? hello.get(scores);? ???? }??? public void get(int scores[]){?? ??? ?for (int i = 0; i < scores.length; i++) {?? ??? ??? ?if (scores[i]>100 || scores[i]<0) scores[i]=0;?? ??? ?}????? for (int i = 0; i < scores.length; i++) {?? ??? ?for (int j = 0; j < scores.length-1-i; j++) {?? ??? ??? ?if(scores[j]<scores[j+1]){?? ??? ??? ??? ?//交換位置?? ??? ??? ??? ?scores[j]=scores[j]+scores[j+1];?? ??? ??? ??? ?scores[j+1]=scores[j]-scores[j+1];?? ??? ??? ??? ?scores[j]=scores[j]-scores[j+1];?? ??? ??? ?}?? ??? ?}?? ?}?? ???? ?????? System.out.println("");????? //System.out.println(scores[t-1]+"\n"+scores[t-2]+"\n"+scores[t-3]);????? System.out.println(scores[0]+"\n"+scores[1]+"\n"+scores[2]);???? }}
chen7841835 提問者
你都沒判斷 ,?
舉報
0基礎(chǔ)萌新入門第一課,從Java環(huán)境搭建、工具使用、基礎(chǔ)語法開始
4 回答為什么會輸出兩個結(jié)果呢?
3 回答println(SEXM+SEXW)為什么會輸出數(shù)字?
2 回答為什么會輸出119
2 回答為什么會說我輸出錯誤呢?輸出結(jié)果就是:它是個3位數(shù)!
1 回答為什么輸出的是數(shù)字
Copyright ? 2025 imooc.com All Rights Reserved | 京ICP備12003892號-11 京公網(wǎng)安備11010802030151號
購課補貼聯(lián)系客服咨詢優(yōu)惠詳情
慕課網(wǎng)APP您的移動學(xué)習(xí)伙伴
掃描二維碼關(guān)注慕課網(wǎng)微信公眾號
2015-04-19
為什么樓主要自己定義方法排序呢?有sort方法啊。會簡潔不少。
2015-03-26
a=3;
并不是a就是3,而是a指向3
所以
int a,b;
a=a+b;
b=a-b;
a=a-b;
這樣可以交換這兩個數(shù)...
2015-03-26
package com.rui.text;
public class JavaDemoTest {
?? ?
??? public static void main(String[] args) {
?? ??? ?JavaDemoTest hello=new JavaDemoTest();
??????? int []scores={89,-23,64,91,119,52,73};
?? ?
??????? hello.get(scores);? ?
??? }
??? public void get(int scores[]){
?? ??? ?for (int i = 0; i < scores.length; i++) {
?? ??? ??? ?if (scores[i]>100 || scores[i]<0) scores[i]=0;
?? ??? ?}
????? for (int i = 0; i < scores.length; i++) {
?? ??? ?for (int j = 0; j < scores.length-1-i; j++) {
?? ??? ??? ?if(scores[j]<scores[j+1]){
?? ??? ??? ??? ?//交換位置
?? ??? ??? ??? ?scores[j]=scores[j]+scores[j+1];
?? ??? ??? ??? ?scores[j+1]=scores[j]-scores[j+1];
?? ??? ??? ??? ?scores[j]=scores[j]-scores[j+1];
?? ??? ??? ?}
?? ??? ?}
?? ?}?? ?
??? ?
????? System.out.println("");
????? //System.out.println(scores[t-1]+"\n"+scores[t-2]+"\n"+scores[t-3]);
????? System.out.println(scores[0]+"\n"+scores[1]+"\n"+scores[2]);
?
??? }
}
2015-03-26
你都沒判斷 ,?