急急急。。..编写JAVA程序,要求从键盘输入10个整数,然后对这10个数进行降序排序并输出。

如题所述

很好写呀、我懒的去敲了。如果这个不会的话也就是你们刚学,所以自己敲吧!

分别获取10个int值 然后比大小就OK了。有现成函数的!
温馨提示:答案为网友推荐,仅供参考
第1个回答  2009-09-22
public class Sort {
//public Sort(){}
public static void main(String args[]){
int[] num = new int[10] ;
int N = num.length ;
int temp = 0 ;

try{
for(int i=0 ; i<10 ; i++){
num[i] = Integer.parseInt(args[i]) ;
}

//排序开始
for(int i=0 ; i<N-1 ; i++){
for(int j=N-2 ; j>=i ; j--){
if(num[j]>num[j+1]){
temp = num[j] ;
num[j] = num[j+1] ;
num[j+1] = temp ;
}
}
}
//输出排序结果
for(int i=0; i<N; i++){
System.out.println(num[i]);
}
}catch(Exception ex){
//ex.printStackTrace() ;
}

}

}

编译:javac Sort.java

运行:java Sort 1 4 7 8 5 2 3 6 9 0

结果:0 1 2 3 4 5 6 7 8 9

典型的冒泡排序

键盘输入的话
try{
for(int i=0 ; i<10 ; i++){
num[i] = Integer.parseInt(args[i]) ;
}
这句话改成System in就行了(从控制台输入太久没用...忘了)本回答被网友采纳
第2个回答  推荐于2018-04-07
import java.io.*;
import java.util.*;
public class A
{
public static void main(String[] args) throws NumberFormatException, IOException
{
int[] num=new int[10];
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
for(int i=0;i<10;i++)
{
System.out.println("请输入第"+(i+1)+"个数:");
int temp=Integer.parseInt(br.readLine());
num[i]=temp;
}
Arrays.sort(num);
for(int i=num.length-1;i>=0;i--)
{
System.out.print(num[i]+" ");
}
}
}本回答被网友采纳
第3个回答  2009-09-22
自己做!