import java.util.ArrayList;
import java.util.Random;
class randomTest {
/**
* @param args
*/
public static void main(String[] args) {
Random r = new Random();
ArrayList al = new ArrayList();
for(int y=0;y<5;y++){
int x = r.nextInt(10);
al.add(x);
}
int size = al.size();
int[] arr = new int[size];
for(int x=0;x<al.size();x++){
arr[x] = Integer.parseInt(al.get(x).toString());
}
for(int y=0;y<arr.length;y++){
System.out.print(arr[y]+",");
}
System.out.println();
for(int x=0;x<arr.length-1;x++){
for(int y=0;y<arr.length-1-x;y++){
if(arr[y]>arr[y+1]){
int temp = arr[y];
arr[y] = arr[y+1];
arr[y+1] = temp;
}
}
}
for(int y=0;y<arr.length;y++){
System.out.print(arr[y]+",");
}
}
}
|
|