Created
March 9, 2016 14:08
-
-
Save melnikovdv/da02b009c63a46a9d246 to your computer and use it in GitHub Desktop.
Склонятор числительных
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 plural(long n, String form1, String form2, String form3) { | |
n = Math.abs(n); | |
int plural = (n % 10 == 1 && n % 100 != 11 ? 0 : (n % 10 >= 2 && n % 10 <= 4 && (n % 100 < 10 || n % 100 >= 20) ? 1 : 2)); | |
switch (plural) { | |
case 1: | |
return form2; | |
case 2: | |
return form3; | |
default: | |
return form1; | |
} | |
} | |
// text = plural(count, "минута", "минуты", "минут"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment