Results 1 to 2 of 2
  1. #1
    iceyferrara is offline Member
    Join Date
    Sep 2011
    Rep Power

    Default Cannot find symbol for selection sort algorithm

    My problem is that my compiler tells me it cannot find my selectionSort method when i call it. Can some one help?

    heres my code, in two classes, cuz thats how its gotta be done.

    Java Code:
    import java.util.*;
    public class NumberArray
    	public static void main(String[] args) throws IOException
    		Scanner keyboard = new Scanner(;			//Create Scanner object so user can input the file name
    		System.out.println("Please enter the name of the file with the numbers you were given:");
    		String givenNumbers = keyboard.nextLine(); 			//Store the filename to a string varaible
    		File file = new File("givenNumbers");				// Use the variable to open a new file
    		Scanner inputFile = new Scanner(file);				// Scanner inputFile allows the numbers in the file to be read
    		int index = 0;
    		double[] fileNumbers;								//Set index to 0 and create a double array to store numbers for sort
    		while (inputFile.hasNext())
    			fileNumbers[index] = inputFile.nextDouble();	//Since each number is on a new line in the file, this will store the numbers into the array
    		inputFile.close();									//Close the file
    Java Code:
    import java.util.*;
    public class NumberAnalysis
        public static void selectionSort(double[] numbers)
            int scan, index, minIndex, maxIndex;
            double maxValue, minValue, average, total;  // Declare variables to store max and min values
            total = 0.0;                                // and their indexs, along with scan, average and total
            maxValue = 0.0;                             // Initialize these variables before loop so can be called after
            minValue = 0.0;
            for(scan = 0; scan < (numbers.length-1); scan++)
                minIndex = scan;
                minValue = numbers[scan];                   //Scan represents first index of array, 0
                for(index = scan + 1; index < numbers.length; index++)
                    if (numbers[index] < minValue)
                        minValue = numbers[index];          //This if statement sorts the array throughout the whole
                        minIndex = index;                   //for loop. From lowest to higest numbers
                numbers[minIndex] = numbers[scan];
                numbers[scan] = minValue;
                total = total + numbers[scan];
            maxIndex = numbers.length - 1;                  //Selection sort makes the last index in the array the highest number so assign that to maxIndex
            maxValue = numbers[maxIndex];                   //maxValue is equal to the last number in the array so call it using maxIndex
            average = (total / numbers.length);
            System.out.println("The lowest number in the array is: " + minValue +
                                "\nThe highest number in the array is: " + maxValue +
                                "\nThe total of all the numbers in the array is: " + total +
                                "\nThe average of all the numbers in the array is : " + average);

    The first set of code is the one with the error, the second set of code compiles correctly. I appreciate any help or insight on my problem. Thank you

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Blog Entries
    Rep Power

Similar Threads

  1. Selection Sort Algorithm Not Working
    By flubbernugget in forum New To Java
    Replies: 8
    Last Post: 07-20-2011, 01:18 AM
  2. Is this a Selection Sort?
    By Metastar in forum New To Java
    Replies: 2
    Last Post: 10-22-2010, 05:00 AM
  3. Replies: 9
    Last Post: 10-18-2008, 08:26 PM
  4. Replies: 3
    Last Post: 05-01-2008, 08:30 AM
  5. How to sort a list using Bubble sort algorithm
    By Java Tip in forum Algorithms
    Replies: 3
    Last Post: 04-29-2008, 08:04 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts