@nen0y

Как вызвать метод из другого класса?

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));
    }

}


Пытаюсь вызвать в main

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
  • Вопрос задан
  • 697 просмотров
Решения вопроса 1
netrox
@netrox
Вы передаёте массив конструктору.
public class Main {

    public static void main(String[] args){
        
        int[] unsortedArray = {2, 16, 5, 1, 8, 21, 4};
        
         BubbleSort instance =new BubbleSort();
         instance.bubbleSort(unsortedArray );
        
    }
    
}
Ответ написан
Комментировать
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы
Bell Integrator Ульяновск
До 400 000 ₽
Bell Integrator Ижевск
До 400 000 ₽
Bell Integrator Хабаровск
До 400 000 ₽