public class MinMaxMean {
public int min;
public int max;
public int mean;
public int diff;
public static MinMaxMean calculate(int... scores) {
MinMaxMean result = new MinMaxMean();
List scoreList = Arrays.asList(scores);
// sort the list
Collections.sort(scoreList);
result.min = scoreList.get(0);
result.max = scoreList.get(soreList.size()-1);
result.diff = max - min;
int sum = 0;
for (int score : scoreList) {
sum += score;
}
result.mean = sum / scoreList.size();
return result;
}
}
여러가지 방법이 있을 수 있겠고, 그중 Collections 와 List를 이용한 방법입니다. Collection와 Array의 sort 메소드를 참조해 보세요.