diff --git a/algorithms/Java/sorting/bubble-sort.java b/algorithms/Java/sorting/bubble-sort.java index 61b88316..65819b9b 100644 --- a/algorithms/Java/sorting/bubble-sort.java +++ b/algorithms/Java/sorting/bubble-sort.java @@ -1,27 +1,40 @@ +import java.util.Scanner; +public class sorting { + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); -import java.util.Arrays; + boolean sorted = true; -public class BubbleSort { - static int temp = 0; - static int[] nums = { 13, 34, 12, 45, 56, 32, 20 }; + System.out.println("Enter the size of array: "); + int n=sc.nextInt(); - public static void main(String[] args) { + int a[]=new int[n]; - System.out.println("Before Sorting : "+Arrays.toString(nums)); - sort(); + System.out.println("Enter the elements of array : "); + for (int i=0;i nums[i]) { - temp = nums[j]; - nums[j] = nums[i]; - nums[i] = temp; - } - } - } - System.out.println(Arrays.toString(nums)); - } -} \ No newline at end of file + for (int i=0;i