package game
;
public class two {
	public static void main(String
[] args
) {
		System
.out
.println("排序前:");
int arr
[]=new int[30];                   
for (int i 
= 0; i 
< arr
.length
; i
++) {
	arr
[i
]=(int)(Math
.random()*100)+1;   
	
		System
.out
.print(arr
[i
]+" ");
 
}
for (int i 
= 0; i 
< arr
.length
; i
++) {   
for (int j 
= 0; j 
< arr
.length
-1; j
++) { 
	if(arr
[j
]>arr
[j
+1]) {                
		int t
=arr
[j
];                    
		arr
[j
]=arr
[j
+1];
		arr
[j
+1]=t
;
}
}	
}
System
.out
.println();                     
System
.out
.println("排序后:");
for (int i 
= 0; i 
< arr
.length
; i
++) {    
	System
.out
.print(arr
[i
]+" ");         
}
}
}
 
结果: 1.加System.out.println(); 前 排序前: 16 65 17 6 23 94 52 59 80 67 95 20 9 78 25 90 5 17 79 86 89 76 42 52 8 15 81 31 100 40 排序后: 5 6 8 9 15 16 17 17 20 23 25 31 40 42 52 52 59 65 67 76 78 79 80 81 86 89 90 94 95 100 2.加加System.out.println(); 后
 
排序前:
93 34 96 20 90 39 17 6 35 64 65 39 7 68 71 63 78 2 69 65 31 48 37 80 45 21 29 77 76 94 
排序后:
2 6 7 17 20 21 29 31 34 35 37 39 39 45 48 63 64 65 65 68 69 71 76 77 78 80 90 93 94 96 
 
1> 输入随机数的时候,还可以用导包的形式,在这里就不多说了。 2>一定要注意数组下标是否越界。