-
Notifications
You must be signed in to change notification settings - Fork 693
/
Solution.java
35 lines (31 loc) · 915 Bytes
/
Solution.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
//Problem: https://www.hackerrank.com/challenges/mini-max-sum
//Java 8
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
public class Solution {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
long min = Long.MAX_VALUE;
long max = 0;
long sum = 0;
for(int i=0; i<5; i++)
{
long curr = in.nextLong();
if(max < curr)
{
max = curr;
}
if(min > curr)
{
min = curr;
}
sum += curr;
}
long minSum = sum - max;//Removes the largest of the 5 numbers to get the min sum
long maxSum = sum - min;//Removes the smallest of the 5 numbers to get the max sum
System.out.println(minSum + " " + maxSum);
}
}