Skip to content

Instantly share code, notes, and snippets.

@nikartm
Last active December 11, 2017 13:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nikartm/1c3041538d9f22713ad29aa5452c0b75 to your computer and use it in GitHub Desktop.
Save nikartm/1c3041538d9f22713ad29aa5452c0b75 to your computer and use it in GitHub Desktop.
Склонение возраста (ru)
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