JAVA Syntax Meaning Inquiry

Asked 2 weeks ago, Updated 2 weeks ago, 1 views

public class BubbleSort{

public static void bubbleSort(int[] arr) {
    for(int i = 0; i < arr.length; i++) {
        for(int j = 0; j < arr.length - i -1 ; j++) {
            if(arr[j] > arr[j+1]) {
                int temp = arr[j+1];
                arr[j+1] = arr[j];
                arr[j] = temp;
            }
        }
    }
}
public static void main(String[] args) {
    int[] arr = new int[]{3,6,41,2,4,1,5,743};
    BubbleSort Sort = new BubbleSort();
    Sort.bubbleSort(arr);
    for(int i : arr) { 
        System.out.print(i+" ");
    }
}

}

I'm inquiring because there's a sentence that I don't understand while I'm trying to find the bubble sort function. If you look at the highlighted syntax,

Class name (BubbleSort) Any letter = new class name (BubbleSort)();

Any letter.bubbleSort(arr);

The 'for' statement below turns when the phrase above goes in. I'd appreciate it if you could tell me what this means and why you need it.

java class

2022-09-20 16:25

1 Answers

First of all, I think you should know what classes and instances are.

To give you a simple example, you can compare the class to a mold and the instance to a mold, but if you search on Google, you can find a more detailed explanation. If you understand this, I think your question will be solved.


2022-09-20 16:25

If you have any answers or tips


© 2022 pinfo. All rights reserved.