hello,
I am having trouble with a program. It seems easy, but for some reason I am just not getting it. I need to create an array of random numbers and call a bubblesort method that I create myself. I then need to print the sorted array. I created the random array but I cant seem to figure out the sort method, which needs to follow in descending order. This is what I have:
[CODE=java] public static int[] sorting(int vals[])
{
int i,j;
int max[] = new int [vals.length];
System.arraycop y(vals,0,max,0, vals.length);
for (i = 1; i < vals.length; i++)
{
for (j = 1; j < max.length; j++)
{
if (vals[j-1] > vals[j])
{
max[j-1] = vals[j];
max[j] = vals[j-1];
}
}
}
return max;
}
}[/CODE]
The message I am getting is the random numbers (the number of numbers is defined by the user and i printed the numbers just to see if it worked) along with the message [I@1eed786.
Please help,
Thanks
I am having trouble with a program. It seems easy, but for some reason I am just not getting it. I need to create an array of random numbers and call a bubblesort method that I create myself. I then need to print the sorted array. I created the random array but I cant seem to figure out the sort method, which needs to follow in descending order. This is what I have:
[CODE=java] public static int[] sorting(int vals[])
{
int i,j;
int max[] = new int [vals.length];
System.arraycop y(vals,0,max,0, vals.length);
for (i = 1; i < vals.length; i++)
{
for (j = 1; j < max.length; j++)
{
if (vals[j-1] > vals[j])
{
max[j-1] = vals[j];
max[j] = vals[j-1];
}
}
}
return max;
}
}[/CODE]
The message I am getting is the random numbers (the number of numbers is defined by the user and i printed the numbers just to see if it worked) along with the message [I@1eed786.
Please help,
Thanks
Comment