A few people asked me how to sort an array with random numers so i wrapped up a small demo for them.
Here it is:
GeSHi (java):
/*--------------------------------------------------------------------------
//By: Ark de Appel
//Date: 1 DEC 2007
//Home: www.engineeringserver.com
//----------------------------------------------------------------------*/
import java.util.Arrays;
import java.util.Scanner;
public class Array20 {
static int[] ar;
static boolean run = true;
static int i = 0;
public static void main
(String[] args
){ Scanner sc =
new Scanner
(System.
in);
System.
out.
print("How many elements in the array?: ");
int intRead =
Integer.
parseInt(read
);
try{
ar = new int[intRead];
for (i = 0; i < intRead; i++){
ar
[i
] =
(int)(50*
Math.
random()+1);
} System.
out.
print("Unsorted array:\t ");
for (i = 0; i < ar.length; i++){
System.
out.
print(ar
[i
] +
" ");
}
System.
out.
print("Sorted array:\t ");
for (i = 0; i < ar.length; i++){
System.
out.
print(ar
[i
] +
" ");
}
}
AIOOE.printStackTrace();
}
}
}
Created by GeSHI 1.0.7.20