-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAgeCalculation.java
More file actions
42 lines (34 loc) · 1007 Bytes
/
AgeCalculation.java
File metadata and controls
42 lines (34 loc) · 1007 Bytes
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
package MethodsComputer;
public class AgeCalculation {
public static int digitsSum(int num) {
int sum = 0;
while (num > 0) {
sum += num % 10;
num /= 10;
}
return sum;
}
public static int digitsProduct(int num) {
int product = 1;
while (num > 0) {
product *= num % 10;
num /= 10;
}
return product;
}
public static void findAges() {
for (int m = 10; m < 100; m++) {
int maxAgeNow = digitsSum(m);
int maxAgeInFiveYears = maxAgeNow + 5;
int minFiveYears = m + 5;
int productOfDigits = digitsProduct(minFiveYears);
if (maxAgeInFiveYears == productOfDigits) {
System.out.printf("Сегодня Максу %d лет, а Морицу %d лет.%n", maxAgeNow, m);
return;
}
}
}
public static void main(String[] args) {
findAges();
}
}