From 1b60fcf259ba8cb1fcfed0576ffc26f06bef1543 Mon Sep 17 00:00:00 2001 From: ABILASH9966 <54049166+ABILASH9966@users.noreply.github.com> Date: Fri, 1 Oct 2021 07:06:23 +0530 Subject: [PATCH] Create Greatest Number --- Greatest Number | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 Greatest Number diff --git a/Greatest Number b/Greatest Number new file mode 100644 index 0000000..2745d04 --- /dev/null +++ b/Greatest Number @@ -0,0 +1,23 @@ +public class LargestInArrayExample{ +public static int getLargest(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[total-1]; +} +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("Largest: "+getLargest(a,6)); +System.out.println("Largest: "+getLargest(b,7)); +}}