From 04bb2c07f743c1dc5abe4f114a0296770837773c Mon Sep 17 00:00:00 2001 From: NoobArvind <73385144+NoobArvind@users.noreply.github.com> Date: Sat, 24 Oct 2020 15:37:01 +0530 Subject: [PATCH] java-program-to-find-smallest-number-in-an-array java-program-to-find-smallest-number-in-an-array --- small | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 small diff --git a/small b/small new file mode 100644 index 0000000..91db588 --- /dev/null +++ b/small @@ -0,0 +1,23 @@ +public class SmallestInArrayExample{ +public static int getSmallest(int[] a, int total){ +int temp; +for (int i = 0; i < total; i++) + { + for (int j = i + 1; j < total; j++) + { + if (a[i] > a[j]) + { + temp = a[i]; + a[i] = a[j]; + a[j] = temp; + } + } + } + return a[0]; +} +public static void main(String args[]){ +int a[]={1,2,5,6,3,2}; +int b[]={44,66,99,77,33,22,55}; +System.out.println("Smallest: "+getSmallest(a,6)); +System.out.println("Smallest: "+getSmallest(b,7)); +}}