Skip to content

Commit 653ebcd

Browse files
committed
Day 3 ques-1
0 parents  commit 653ebcd

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

LargestPerimeter.java

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import java.util.Arrays;
2+
3+
public class LargestPerimeter
4+
{
5+
public static void main(String[] args)
6+
{
7+
int[] sides = {1,2,1,10};
8+
System.out.println(perimeterCalculator(sides));
9+
}
10+
11+
static int perimeterCalculator(int[] array)
12+
{
13+
Arrays.sort(array);
14+
for (int i = array.length-3; i>=0; i--)
15+
{
16+
if (array[i]+array[i+1] > array[i+2])
17+
{
18+
return array[i]+array[i+1]+array[i+2];
19+
}
20+
}
21+
return 0;
22+
}
23+
}

0 commit comments

Comments
 (0)