forked from Yandex-Practicum/Java-Module-Project-YP
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRubend.java
More file actions
30 lines (25 loc) · 842 Bytes
/
Rubend.java
File metadata and controls
30 lines (25 loc) · 842 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
public class Rubend {
private static final String RUB = "рубль";
private static final String RUBL = "рубля";
private static final String RUBLS = "рублей";
public static String formatter(double priceForOne) {
int format = (int) Math.floor(priceForOne);
int endNumber10 = format % 10;
int endNumber100 = format % 100;
String ending ;
while (true) {
if (endNumber10 == 1 && endNumber100 != 11) {
ending = RUB;
break;
} else if ((endNumber10 >= 2 && endNumber10 <= 4) && (endNumber100 < 10 || endNumber100 >= 20)) {
ending = RUBL;
break;
}
else {
ending = RUBLS;
break;
}
}
return ending;
}
}