日期:2014-05-20 浏览次数:20709 次
int []arr=new int[10];
System.out.println("随机数的顺序是:");
for(int a = 0 ;a<10;a++){
int random = (int) (Math.random()*100);
arr[a]=random;
System.out.print(" "+random);
}
System.out.println();
System.out.println("正序是");
for(int b :arr){
System.out.print(" "+b);
}
System.out.println();
System.out.println("逆序是:");
for(int c = 9;c>=0;c--){
System.out.print(" "+arr[c]);
}
public class Test {
public static void main(String[] args) {
int a[] = new int[10];
for(int i=0;i<a.length;i++){
a[i] = (int)(Math.random()*100);
}
Arrays.sort(a);
//升序
System.out.println("升序");
for(int i=0;i<a.length;i++){
System.out.print(a[i] + " ");
}
System.out.println();
//降序
System.out.println("降序");
for(int i=a.length-1;i>=0;i--){
System.out.print(a[i] + " ");
}
System.out.println();
}
}
for (int i = 0; i<arr.length;i++){
arr[i] = (int)(Math.random() * 100);
}
System.out.println(Arrays.toString(arr));