Computer Science, asked by irenemaria42, 4 months ago

write a program in java to perform bubble sort in ascending order of integer array​

Answers

Answered by Anonymous
1

Answer:

Bubble Sort in Java

1)public class BubbleSortExample {

2)static void bubbleSort(int[] arr) {

3)int n = arr.length;

4)int temp = 0;

5)for(int i=0; i < n; i++){

6)for(int j=1; j < (n-i); j++){

7)if(arr[j-1] > arr[j]){

8)//swap elements.

import java.util.Scanner;

class BubbleSortExample {

public static void main(String []args) {

int num, i, j, temp;

Scanner input = new Scanner(System.in);

System.out.println("Enter the number of integers to sort:");

num = input.nextInt();

int array[] = new int[num];

System.out.println("Enter " + num + " integers: ");

for (i = 0; i < num; i++)

array[i] = input.nextInt();

for (i = 0; i < ( num - 1 ); i++) {

for (j = 0; j < num - i - 1; j++) {

if (array[j] > array[j+1])

{

temp = array[j];

array[j] = array[j+1];

array[j+1] = temp;

}

}

}

System.out.println("Sorted list of integers:");

for (i = 0; i < num; i++)

System.out.println(array[i]);

}

}

Answered by bhagyashiri932010
2

hope this helps you see full photo please mark me brand list I need

Attachments:
Similar questions