My code isn't working and I need help. The ones in BOLD are where the error is
Question:
My code isn't working and I need help. The ones in BOLD are where the error is happing
** * */ package programming2ass1;
/** * @author tia * */
public class Programming2ass1 {
private static final String Arrays = null; /** * @param args */ int MaxSizeoftheArray=100000; // The size of the array int[] sortArray1 = new int[MaxSizeoftheArray]; // The first Array int[] sortArray2 = new int[MaxSizeoftheArray]; // The second Array public Programming2ass1(){ for (int i = 0; i < sortArray1.length; i++) { // Filling two arrays with the same random numbers. sortArray1[i]=(int)(Integer.MAX_VALUE * Math.random()); sortArray2[i]=sortArray1[i]; } long startTimeArray1 = System.currentTimeMillis(); // The start computing time for the first array selectionSort(sortArray1); // Sorting the first Array with SelectionSort long runTimeArray1 = System.currentTimeMillis() - startTimeArray1; // Time take to run theSelectionSort method
long startTimeArray2 = System.currentTimeMillis();// The start computing time for the Arrays.sort method Arrays.sort(sortArray2); // Sorting the second array with Arrays.sort long runTimeArray2 = System.currentTimeMillis() - startTimeArray2; // Time to run the Arrays.sort method System.out.println("SelectionSort time(sec):"+runTimeArray1/1000.0); // Printing of the results System.out.println("Array Sort time(sec):"+runTimeArray2/1000.0); // Printing of the results } static void selectionSort(int[] A) { // Sort A into increasing order, using selection sort for (int lastPlace = A.length-1; lastPlace > 0; lastPlace--) { // Find the largest item among A[0], A[1], ..., // A[lastPlace], and move it into position lastPlace // by swapping it with the number that is currently // in position lastPlace. int maxLoc = 0; // Location of largest item seen so far. for (int j = 1; j <= lastPlace; j++) { if (A[j] > A[maxLoc]) { // Since A[j] is bigger than the maximum we've seen // so far, j is the new location of the maximum value // we've seen so far. maxLoc = j; } } int temp = A[maxLoc]; // Swap largest item with A[lastPlace]. A[maxLoc] = A[lastPlace]; A[lastPlace] = temp; } // end of for loop }
/** * @param args the command line arguments */ @SuppressWarnings("unused") public static void main(String[] args) { Programming2ass1 assignment1 = new Programming2ass1(); }
}
Auditing A Practical Approach
ISBN: 9780730382645
4th Edition
Authors: Robyn Moroney, Fiona Campbell, Jane Hamilton