Last active
December 11, 2017 13:45
-
-
Save nikartx/1c3041538d9f22713ad29aa5452c0b75 to your computer and use it in GitHub Desktop.
Склонение возраста (ru)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static String getAgeWithDeclination(double age){ | |
String result; | |
List<Double> units = Arrays.asList(2d, 3d, 4d); | |
List<Double> dozens = Arrays.asList(11d, 12d, 13d, 14d); | |
if(age != 11 && age % 10 == 1) { | |
result = age + " год"; | |
} else if(age % 1 != 0d || (units.contains(age % 10) && !dozens.contains(age % 100))) { | |
result = age + " года"; | |
} else { | |
result = age + " лет"; | |
} | |
return result; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment