BubbleSort using Java

package com.java.basicprograms;

import java.util.*;

public class BubbleSort {

public static void main(String[] args) {
int num, temp;
System.out.println("Enetr the nuumber of integers to sort");
Scanner sc = new Scanner(System.in);
num = sc.nextInt();
int array[] = new int[num];
System.out.println("Enter the numbers");
for (int i = 0; i < num; i++)
array[i] = sc.nextInt();

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

for (int 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("After sorting thr data is:  ");
for (int i = 0; i < num; i++)
System.out.println(array[i]);

}

}

Comments

Popular posts from this blog

WebPage Design Using HTML and CSS

How to design webpage using HTML And CSS

Convert XML In To Java Using Java