1.[文件] 输入m个数并为其排序 ~ 1KB 下载(26)
package ch1;
import java.util.Scanner;
class test3
{
public static void main(String [] args)
{
System.out.println("为m个数排序。");
System.out.print("请输入数m:");
Scanner sca=new Scanner(System.in);
int m=sca.nextInt();
int i,j,tmp;
int [] a = new int [m];
System.out.println("请输入m个数:");
for(i=0;i
{
a[i]=sca.nextInt();
}
System.out.print("排序前的数:");
for(i=0;i
{
System.out.print(a[i]+" ");
}
System.out.println();
for(i=0;i
{
for(j=m-1;j>i;j--)
{
if(a[j-1]>a[j])
{
tmp=a[j];
a[j]=a[j-1];
a[j-1]=tmp;
}
}
}
System.out.print("排序后的数:");
for(i=0;i
System.out.print(a[i]+" ");
System.out.println();
}
}