Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- String generate(int age) {
- int age = list.get(position).getAge();
- int lastChar = Integer.parseInt((""+age).substring((""+age).length()-1, (""+age).length()));
- String old = "";
- if (age==11) old = "лет";
- else if((""+age).endsWith("1")) old = "год";
- else if(age>11 && age<15) old = "лет";
- else if(lastChar>1 && lastChar<5) old = "года";
- else old = "лет";
- return old;
- }
- int lastChar = age % 10;
- String old = "";
- if (lastChar == 1)
- old = "год";
- else if(lastChar == 0 || lastChar >= 5 && lastChar <= 9)
- old = "лет";
- else if(lastChar >= 2 && lastChar <= 4)
- old = "года";
- else
- old = "что-то еще";
- =0 означает ноль;
- =1 соответствует ровно 1;
- one - 21, 31, 41 и так далее;
- few - от 2 до 4, от 22 до 24 и так далее;
- many - 0, от 5 до 20, от 25 до 30 и так далее;
- other - для всех прочих чисел (например, дробных).
- int age = 5;
- int lastChar = age % 10;
- String old = "";
- if (lastChar == 1)
- old = "год";
- else if(lastChar == 0 || lastChar >= 5 && lastChar <= 9)
- old = "лет";
- else if(lastChar >= 2 && lastChar <= 4)
- old = "года";
- else
- old = "что-то еще";
- System.out.println(old);
- public static StringBuilder appendAge(StringBuilder, int age) {
- assert age > 0 : "Age must be a positive number";
- double[] limits = {0, 1, 2, 5};
- String[] strings = {"лет", "год", "года", "лет"};
- ChoiceFormat format = new ChoiceFormat(limits, strings);
- int rule = 11 <= (age % 100) && (age % 100) <= 14 ? age : age % 10;
- return builder.append(age).append(' ').append(format.format(selector));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement