課程
/后端開發(fā)
/Java
/Java入門第一季(IDEA工具)升級版
第一部分,輸出成績前三那個題
2017-12-14
源自: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};
? ? ? ? System.out.println("考試成績的前三名為:");
? ? ? ? hello.score(scores);
? ? }
? ? public void score(int [] scores){
? ? ? ? Arrays.sort(scores);
? ? ? ? int num=0;
? ? ? ? for(int i=scores.length-1;i>=0&&num<3;i--){
? ? ? ? ? ? if(scores[i]<0||scores[i]>100)
? ? ? ? ? ? ? ? ? ?continue;
? ? ? ? ? ? ? ? ? ?num++;
? ? ? ? ? ? System.out.println(scores[i]);
? ? ? ?}
? ?}
}
? ??
? ? //完成 main 方法
? ? ?int[] scores={89,-23,64,91,119,52,73};
? ? ? System.out.println("排名前三名的成績是:");
? ? ?HelloWorld hello=new HelloWorld();
? ? ?hello.showTop3(scores);
? ? ?
? ? //定義方法完成成績排序并輸出前三名的功能
? ? public void showTop3(int[] scores){
? ? ? ?int num=0;
? ? ? ? for(int i=scores.length-1;i>=0;i--){
? ? ? ? ? ? if(scores[i]>100||scores[i]<0){
? ? ? ? ? ? ? ? continue;
? ? ? ? ? ? ? ??
? ? ? ? ? ? }
? ? ? ? ? ? num++;
? ? ? ? ? ? if(num>3){
? ? ? ? ? ? ? ? break;
? ? ? ? }
? ? ? ??
?
? ? ? ? HelloWorld hello = new HelloWorld();
? ? ? ? int[] scores = {89,-23,64,91,119,52,73};
? ? ? ? int[] nums = hello.grade(scores);
? ? ? ? System.out.println("前三名是:"+Arrays.toString(nums));
? ? public int[] grade(int[] scores){
? ? ? ? int tem=0;
? ? ? ? for(int i = 0;i < scores.length;i++){
? ? ? ? ? ? for(int j = 0;j < scores.length-1;j++){
? ? ? ? ? ? ? ? if(scores[j] <scores[j+1]){
? ? ? ? ? ? ? ? ? ? tem = scores[j+1];
? ? ? ? ? ? ? ? ? ? scores[j+1] = scores[j];
? ? ? ? ? ? ? ? ? ? scores[j] = tem;
? ? ? ? ? ? ? ? }
? ? ? ? int[] nums = {scores[0],scores[1],scores[2]};
? ? ? ? return nums;
? ? } ?
舉報
0基礎(chǔ)萌新入門第一課,從Java環(huán)境搭建、工具使用、基礎(chǔ)語法開始
2 回答編程練習(xí)答案在哪里
2 回答編程題3-8,求答案
2 回答答案錯在哪里
5 回答前輩救援!求3-8編程題答案
3 回答求助,答案在哪里?
Copyright ? 2025 imooc.com All Rights Reserved | 京ICP備12003892號-11 京公網(wǎng)安備11010802030151號
購課補(bǔ)貼聯(lián)系客服咨詢優(yōu)惠詳情
慕課網(wǎng)APP您的移動學(xué)習(xí)伙伴
掃描二維碼關(guān)注慕課網(wǎng)微信公眾號
2017-12-25
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};
? ? ? ? System.out.println("考試成績的前三名為:");
? ? ? ? hello.score(scores);
? ? }
? ? public void score(int [] scores){
? ? ? ? Arrays.sort(scores);
? ? ? ? int num=0;
? ? ? ? for(int i=scores.length-1;i>=0&&num<3;i--){
? ? ? ? ? ? if(scores[i]<0||scores[i]>100)
? ? ? ? ? ? ? ? ? ?continue;
? ? ? ? ? ? ? ? ? ?num++;
? ? ? ? ? ? System.out.println(scores[i]);
? ? ? ?}
? ?}
}
? ??
2017-12-15
import java.util.Arrays;
public class HelloWorld {
? ? //完成 main 方法
? ? public static void main(String[] args) {
? ? ?int[] scores={89,-23,64,91,119,52,73};
? ? ? System.out.println("排名前三名的成績是:");
? ? ?HelloWorld hello=new HelloWorld();
? ? ?hello.showTop3(scores);
? ? ?
? ?}
? ? //定義方法完成成績排序并輸出前三名的功能
? ??
? ? public void showTop3(int[] scores){
? ? ? ? Arrays.sort(scores);
? ? ? ?int num=0;
? ? ? ? for(int i=scores.length-1;i>=0;i--){
? ? ? ? ? ? if(scores[i]>100||scores[i]<0){
? ? ? ? ? ? ? ? continue;
? ? ? ? ? ? ? ??
? ? ? ? ? ? }
? ? ? ? ? ? num++;
? ? ? ? ? ? if(num>3){
? ? ? ? ? ? ? ? break;
? ? ? ? ? ? }
? ? ? ? ? ? System.out.println(scores[i]);
? ? ? ? }
? ? ? ??
? ? }
?
}
2017-12-14
import java.util.Arrays;
public class HelloWorld {
? ??
? ? //完成 main 方法
? ? public static void main(String[] args) {
? ? ? ? HelloWorld hello = new HelloWorld();
? ? ? ? int[] scores = {89,-23,64,91,119,52,73};
? ? ? ? int[] nums = hello.grade(scores);
? ? ? ? System.out.println("前三名是:"+Arrays.toString(nums));
? ? ? ??
? ? ? ??
? ? }
? ??
? ? //定義方法完成成績排序并輸出前三名的功能
? ? public int[] grade(int[] scores){
? ? ? ? int tem=0;
? ? ? ? for(int i = 0;i < scores.length;i++){
? ? ? ? ? ? for(int j = 0;j < scores.length-1;j++){
? ? ? ? ? ? ? ? if(scores[j] <scores[j+1]){
? ? ? ? ? ? ? ? ? ? tem = scores[j+1];
? ? ? ? ? ? ? ? ? ? scores[j+1] = scores[j];
? ? ? ? ? ? ? ? ? ? scores[j] = tem;
? ? ? ? ? ? ? ? }
? ? ? ? ? ? }
? ? ? ? }
? ? ? ? int[] nums = {scores[0],scores[1],scores[2]};
? ? ? ? return nums;
? ? } ?
}