Advertisement
Guest User

Untitled

a guest
Dec 3rd, 2016
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.68 KB | None | 0 0
  1. String generate(int age) {
  2. int age = list.get(position).getAge();
  3. int lastChar = Integer.parseInt((""+age).substring((""+age).length()-1, (""+age).length()));
  4. String old = "";
  5. if (age==11) old = "лет";
  6. else if((""+age).endsWith("1")) old = "год";
  7. else if(age>11 && age<15) old = "лет";
  8. else if(lastChar>1 && lastChar<5) old = "года";
  9. else old = "лет";
  10. return old;
  11. }
  12.  
  13. int lastChar = age % 10;
  14.  
  15. String old = "";
  16.  
  17. if (lastChar == 1)
  18. old = "год";
  19. else if(lastChar == 0 || lastChar >= 5 && lastChar <= 9)
  20. old = "лет";
  21. else if(lastChar >= 2 && lastChar <= 4)
  22. old = "года";
  23. else
  24. old = "что-то еще";
  25.  
  26. =0 означает ноль;
  27. =1 соответствует ровно 1;
  28. one - 21, 31, 41 и так далее;
  29. few - от 2 до 4, от 22 до 24 и так далее;
  30. many - 0, от 5 до 20, от 25 до 30 и так далее;
  31. other - для всех прочих чисел (например, дробных).
  32.  
  33. int age = 5;
  34. int lastChar = age % 10;
  35.  
  36. String old = "";
  37. if (lastChar == 1)
  38. old = "год";
  39. else if(lastChar == 0 || lastChar >= 5 && lastChar <= 9)
  40. old = "лет";
  41. else if(lastChar >= 2 && lastChar <= 4)
  42. old = "года";
  43. else
  44. old = "что-то еще";
  45.  
  46. System.out.println(old);
  47.  
  48. public static StringBuilder appendAge(StringBuilder, int age) {
  49. assert age > 0 : "Age must be a positive number";
  50. double[] limits = {0, 1, 2, 5};
  51. String[] strings = {"лет", "год", "года", "лет"};
  52. ChoiceFormat format = new ChoiceFormat(limits, strings);
  53. int rule = 11 <= age && age <= 14 ? age : age % 10;
  54. return builder.append(age).append(' ').append(format.format(selector));
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement