##冒泡 ``` package com.xiaohu; import java.util.Scanner; public class Test1 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); float[] num = new float[5]; for(int i=0;i<5;i++) { num[i]=sc.nextFloat(); } // [100,20,500,30,400] // 0 1 2 3 4 // boolean flag=false; int i,j; float temp; for(i=0;iscores[j+1]) { temp=scores[j]; scores[j]=scores[j+1]; scores[j+1]=temp; } } } for(int i=0;iscores[j+1]) { temp=scores[j]; scores[j]=scores[j+1]; scores[j+1]=temp; } } } for(int k=0;k<5;k++) { System.out.print(scores[k]+"\t"); } for(int i=0;iscores[j+1]) { temp=scores[j]; scores[j]=scores[j+1]; scores[j+1]=temp; t=names[j]; names[j]=names[j+1]; names[j+1]=t; } } } for(int i=0;i<5;i++) { System.out.print(names[i]+"\t"); } System.out.println(""); for(int i=0;i<5;i++) { System.out.print(scores[i]+"\t"); } sc.close(); } } ``` [demo.rar](http://qcdn.imxiaohu.cn/blog/typecho/demo.rar-blog) 最后修改:2024 年 05 月 30 日 © 允许规范转载 打赏 赞赏作者 支付宝微信 赞 如果觉得我的文章对你有用,请随意赞赏