java成绩排名冒泡排序
时间: 2023-08-29 08:11:45 浏览: 118
以下是一个使用冒泡排序算法对Java成绩进行排名的示例代码:
```
import java.util.Scanner;
public class Maopao {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int chengji[] = new int = sc.nextInt();
}
for (int i = 0; i < chengji.length - 1; i++) {
for (int j = 0; j < chengji.length - 1 - i; j++) {
if (chengji[j < chengji[j + 1]) {
int temp = chengji[j];
chengji[j = chengji[j + 1];
chengji[j + 1 = temp;
}
}
}
System.out.print("学员成绩按降序排列为:");
for (int i = 0; i < chengji.length; i++) {
System.out.print(chengji[i + "\t");
}
}
}
```
这段代码使用了冒泡排序算法对输入的5名同学的成绩进行降序排列。首先,用户需要输入5名同学的成绩。然后,两层循环遍历成绩数组,每次比较相邻的两个成绩,如果前面的成绩比后面的成绩小,就交换它们的位置。经过多轮循环后,最大的成绩会被交换到数组的最后。最后,输出排序后的成绩数组。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* [Java输入5名学员成绩进行降序排列(冒泡排序)](https://blog.csdn.net/qq_57480977/article/details/125726130)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}}] [.reference_item style="max-width: 33.333333333333336%"]
- *2* [冒泡排序:对成绩从低到高进行排序(JAVA)](https://blog.csdn.net/weixin_40119412/article/details/78981896)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}}] [.reference_item style="max-width: 33.333333333333336%"]
- *3* [达内 coreJava 习题答案](https://download.csdn.net/download/lq_1987/2058999)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}}] [.reference_item style="max-width: 33.333333333333336%"]
[ .reference_list ]
阅读全文