Answer to Question #208247 in Java | JSP | JSF for Princess

Question #208247

Write a Java program to sort an array of given integers using the Bubble sorting Algorithm ????


1
Expert's answer
2021-06-18T05:49:31-0400
public class BubbleSort {
    public static void main(String[] args) {
        int[] array = {6, 5, 4, 7, 10, 3, 2, 1};

        sort(array);

        for (int j : array) {
            System.out.print("" + j + " ");
        }
        System.out.println();
    }

    public static void sort(int[] array) {
        for (int i = 0; i < array.length - 1; i++) {
            for (int j = 0; j < array.length - 1 - i; j++) {
                if (array[j] > array[j + 1]) {
                    int temp = array[j];
                    array[j] = array[j + 1];
                    array[j + 1] = temp;
                }
            }
        }
    }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS