Results 1 to 2 of 2
- 10-15-2011, 01:03 AM #1
Member
- Join Date
- Sep 2011
- Posts
- 10
- Rep Power
- 0
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.*; import java.io.*; public class NumberArray { public static void main(String[] args) throws IOException { Scanner keyboard = new Scanner(System.in); //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 index++; } selectionSort(fileNumbers); 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
-
Re: Cannot find symbol for selection sort algorithm
Which class does the selectionSort method reside in?
Similar Threads
-
Selection Sort Algorithm Not Working
By flubbernugget in forum New To JavaReplies: 8Last Post: 07-20-2011, 01:18 AM -
Is this a Selection Sort?
By Metastar in forum New To JavaReplies: 2Last Post: 10-22-2010, 05:00 AM -
cannot find symbol symbol :constructor Error. Please help! =(
By KalEl in forum New To JavaReplies: 9Last Post: 10-18-2008, 08:26 PM -
cannot find symbol symbol : class Item location: package platypos.services.order
By officialhopsof in forum New To JavaReplies: 3Last Post: 05-01-2008, 08:30 AM -
How to sort a list using Bubble sort algorithm
By Java Tip in forum AlgorithmsReplies: 3Last Post: 04-29-2008, 08:04 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks