I need to generate 500 random numbers from 200 to 1200 and use insertion to sort them. This is probaly simple for you guys but im confused. My problem is when i run the program all I get is 500 0's. Anyone help me out?
public class insertion{
public static void main(String arg[]){
int n = 500;
int[] a = new int[n];
System.out.println("\n\nInput values:");
for(int i=0;i<n;i++){
System.out.print(" "+a[i]);
}
for (int i = 1; i < a.length; i++) {
int j = i;
int B = 200 + (int)(Math.random() * ((1200 - 200) + 1));
B = a[i];
while ((j > 0) && (a[j-1] > B)) {
a[j] = a[j-1];
j--;
}
a[j] = B;
}
System.out.println("\n\n\nSorted values:");
for(int i=0;i<a.length;i++)
{
System.out.print(" "+a[i]);
}
}
}