[Java] Baekjun number 2480 - three dice
We have summarized the solution for calculating the prize money of three dice using Java conditional statements and Math.max.
한국어 원문은 여기에서 볼 수 있습니다.
[Java] Baekjun number 2480 - three dice
Solution
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
36
37
38
39
40
41
42
43
44
45
46
import java.util.Scanner;
public class Main {
public static void main(String args[]) {
Scanner input = new Scanner(System.in);
int a = input.nextInt();
int b = input.nextInt();
int c = input.nextInt();
if ((a == b) && (b == c)) {
System.out.println(10000 + a*1000);
} else if ((a == b) || (b == c) || (c == a)) {
if (a == b) {
System.out.println(1000 + a*100);
} else if (b == c) {
System.out.println(1000 + b*100);
} else {
System.out.println(1000 + c*100);
}
} else {
int large = 0;
if (a > b) {
if (a > c) {
large = a;
} else {
large = c;
}
} else if (b > c) {
if (b > a) {
large = b;
} else {
large = a;
}
} else {
if (c > b) {
large = c;
} else {
large = b;
}
}
System.out.println(large*100);
}
}
}
Math.max
- A function that returns the larger of two values.
- Finding the maximum value among three values using a conditional statement becomes complicated as a solution, so it can be easily obtained using
Math.max.1
int large = Math.max(a, Math.max(b, c));