-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMission9.java
More file actions
52 lines (46 loc) · 1.06 KB
/
Mission9.java
File metadata and controls
52 lines (46 loc) · 1.06 KB
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
47
48
49
50
51
52
package chapter8;
import java.util.Scanner;
public class Mission9 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int weight = sc.nextInt();
int coreW = weight - 10;
int remW;
int two;
int three;
for (int i = 0; i < 10; i++) {
remW = coreW - i * 5;
int divide2 = remW / 2;
switch (remW % 2) {
case 0:
two = divide2;
three = 0;
if (two > 9) {// skip invalid answers
int count = (two - 7) / 3;// makes two 7, 8 or 9
two -= count * 3;
three += count * 2;
}
printAnswer(two, three, i);
break;
case 1:
two = divide2 - 1;
three = 1;
if (two > 9) {
int count = (two - 7) / 3;
two -= count * 3;
three += count * 2;
}
printAnswer(two, three, i);
break;
}
}
sc.close();
}
private static void printAnswer(int two, int three, int i) {
while (two >= 0 && three <= 9) {
System.out.println("(" + (two + 1) + ", " + (three + 1) + ", " + (i + 1) + ")");
two -= 3;
three += 2;
}
}
}