From ce1cbebaa60f3a6dee1d5443ddc199f3cd5b546f Mon Sep 17 00:00:00 2001 From: PRIYANSH <83279155+Priyansh-777@users.noreply.github.com> Date: Sun, 29 Oct 2023 18:23:56 +0530 Subject: [PATCH] bubble sort java --- Scripts/bubble_sort_exp.java | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 Scripts/bubble_sort_exp.java diff --git a/Scripts/bubble_sort_exp.java b/Scripts/bubble_sort_exp.java new file mode 100644 index 00000000..5e8b260d --- /dev/null +++ b/Scripts/bubble_sort_exp.java @@ -0,0 +1,31 @@ +//Java implementation of Bubble Sort +//Time complexity O(n^2) +import java.util.*; +class bubble_sort_exp{ + public static void main(String args[]){ + Scanner in=new Scanner(System.in); + int a[]=new int[10]; + int i,j,temp; + System.out.println("Enter 10 numbers in SDA"); + for(i=0;i<10;i++) + { + a[i]=in.nextInt(); + } + for(i=0;i<9;i++) + { + for(j=0;j<10-i-1;j++) + { + if(a[j]>a[j+1]){ + temp=a[j]; + a[j]=a[j+1]; + a[j+1]=temp; + } + } + } + System.out.println("Sorted array:"); + for(i=9;i>=0;i--) + { + System.out.println(+a[i]+" "); + } + } +} \ No newline at end of file