//冒泡排序import java.util.*;public class SortDemo{ private static Scanner a; public static void main(String[] args) { int i,j,n,s; a = new Scanner(System.in); System.out.println("您想将多少个数按冒泡排序输出?个数n="); n=a.nextInt(); int args1[] = new int[n]; for(int b=1;b<=n;b++){ System.out.println("请输第"+b+"个数据:"); s=a.nextInt(); args1[b-1]=s; } for(i=0;i<n;i++){ for(j=0;j<n-1;j++){ if(args1[j]>args1[j+1]); {int temp; temp=args1[j]; args1[j]=args1[j+1]; args1[j+1]=temp;} } System.out.println("按从小到大排序后数组元素为:"); for(i=0;i<args1.length;i++){ System.out.print(args1[i]+" "); System.out.println(); } } }}
添加回答
举报
0/150
提交
取消