Home > Net >  How do I fix this issue with package information in Java?
How do I fix this issue with package information in Java?

Time:02-21

I contextualize my problem. I am making a package that contains a main class and other classes that include sorting algorithms, with one of those classes to print arrays and the swap function. Classes in my project: Main.java, quickSort.java, props.java. The problem is that when I want to display that information in the main class nothing is displayed, or I get the following error: method QuickSort in class quickSort cannot be applied to given types;

I don't know the origin of this error, since according to me I am correctly including the method belonging to the quickSort class. So I would appreciate your help.

Also, I included the package well in the class corresponding to quickSort and in the props class too, in case you have any doubts.

Since you asked, here are my quick sort class and props class:

public class quickSort {
 public static int partition(int arr[], int low, int high){
        int pivot = arr[high];
        int i = (low-1);
        for (int j=low; j<high; j  ){
            if (arr[j] <= pivot)
            {
                i  ;
                props.swap(arr, i, j);
            }
        }
        
        int temp = arr[i 1];
        arr[i 1] = arr[high];
        arr[high] = temp;
        return i 1;
    }
    
    public static void QuickSort(int arr[], int low, int high){
        if (low < high){
            int pi = partition(arr, low, high);
            QuickSort(arr, low, pi-1);
            QuickSort(arr, pi 1, high);
        }
    }
}

// This is the code I made for the main class:

package QuickSortAlgorithm;
public class Main {
    public static void main(String args[]){  
        
            int[] arr1 = {17, 90, 2, 8, 11, 98, 4, 6};
            System.out.println("unsorted array:");  
            props.printArray(arr1);
            
            quickSort.QuickSort(arr1);
            System.out.println("sorted array:");
            props.printArray(arr1);
        }
}

// This is the code I made for the props class:

package QuickSortAlgorithm;

public class props {
    
    public static void printArray(int arr[]){
        int n = arr.length;
        for (int i=0; i<n;   i)
            System.out.print(arr[i] " ");
            System.out.println();
 }
    
    public static void swap(int arr[], int i, int j){
        int temp = arr[i];
        arr[i] = arr[j];
        arr[j] = temp;
    }
} 

CodePudding user response:

You need to pass 3 parameters in the call to quickSort.QuickSort():

required: int[],int,int

found: int[]

E.g: quickSort.QuickSort(arr1, 0, 0)
  • Related