Skip to content

Commit 6e489ee

Browse files
Greaterno
Java Program to find Largest Number in an Array
1 parent b0225b7 commit 6e489ee

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
public class LargestInArrayExample{
2+
public static int getLargest(int[] a, int total){
3+
int temp;
4+
for (int i = 0; i < total; i++)
5+
{
6+
for (int j = i + 1; j < total; j++)
7+
{
8+
if (a[i] > a[j])
9+
{
10+
temp = a[i];
11+
a[i] = a[j];
12+
a[j] = temp;
13+
}
14+
}
15+
}
16+
return a[total-1];
17+
}
18+
public static void main(String args[]){
19+
int a[]={1,2,5,6,3,2};
20+
int b[]={44,66,99,77,33,22,55};
21+
System.out.println("Largest: "+getLargest(a,6));
22+
System.out.println("Largest: "+getLargest(b,7));
23+
}}

0 commit comments

Comments
 (0)