PDA

View Full Version : [SOLVED] Java problem



dwally89
October 27th, 2009, 06:29 PM
Hi,

I am currently trying to complete an assign for university and am coming up with a problem whilst writing the following code:


package ex5;
public class Ex5SelectionSort {
// main, sort, findIndexOfNextSmallest, and arrayPrint
public static void main(String[] args){

}
public static void sort(double toBeSorted[]){
for (int i=0; i<toBeSorted.length; i++){
findIndexOfNextSmallest(toBeSorted[], i);
}
}
public static int findIndexOfNextSmallest(double unsorted[], int startIndex){
int minimum=0;
int i=startIndex;
while (i<unsorted.length){
if ((i+1)<unsorted.length){
if (unsorted[i]<unsorted[i+1] && unsorted[i]<minimum){
minimum=i;
}
}
i++;
}
return minimum;
}
}

The line
findIndexOfNextSmallest(toBeSorted[], i); is giving me the error
cannot find symbol
symbol: class toBeSorted
location: class ex5.Ex5SelectionSort

unexpected type
required: value
found: class

'.class' expected

Anyone know what the problem is?

Thanks

shae
October 27th, 2009, 06:40 PM
I think posting a simple case will help you out with your problems passing arrays.


class Test
{
public static void printArray(double[] array)
{
for(double num : array)
System.out.println(num);
}

public static void main(String[] args)
{
double[] nums = { 1.0, 2.0, 3.0, 4.0, 5.0 };

printArray(nums);
}
}

muntasir_120
October 27th, 2009, 08:34 PM
In passing an array as an argument to another method, is the '[]' after its name required? Please consult your Java book.

doas777
October 27th, 2009, 08:37 PM
don't include the '[]' in your argument, but you do need them in the parameter (but I would put them at the end of double rather than after the var name).

dwally89
October 27th, 2009, 11:01 PM
Solved. Thanks.