Answer the question
In order to leave comments, you need to log in
How to call a method from another class?
public class BubbleSort implements Sort{
public void bubbleSort(int[] unsortedArray){
int count = 0;
do{
count = 0;
for(int i = 0; i < unsortedArray.length - 1; i++){
if(unsortedArray[i] > unsortedArray[i + 1]){
int tmp = unsortedArray[i];
unsortedArray[i] = unsortedArray[i + 1];
unsortedArray[i+1] = tmp;
count++;
}
}
}while(count > 0);
System.out.println(Arrays.toString(unsortedArray));
}
}
public class Main {
public static void main(String[] args){
int[] unsortedArray = {2, 16, 5, 1, 8, 21, 4};
Sort bubblesort = new BubbleSort(unsortedArray);
}
}
"The constructor BubbleSort(int[]) is undefined
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question