给你一个下标从 0 开始的字符串
details。details中每个元素都是一位乘客的信息,信息用长度为15的字符串表示,表示方式如下:
- 前十个字符是乘客的手机号码。
- 接下来的一个字符是乘客的性别。
- 接下来两个字符是乘客的年龄。
- 最后两个字符是乘客的座位号。
请你返回乘客中年龄 严格大于 60 岁 的人数。
- class Solution {
- public int countSeniors(String[] details) {
- int count = 0;
- for (int i = 0; i < details.length; i++){
- if(details[i].charAt(11) > '6'){
- count++;
- }
- if(details[i].charAt(11) == '6' && details[i].charAt(12) > '0'){
- count++;
- }
- //方法二
- // int age = Integer.valueOf(details[i].substring(11,13));
- // if(age > 60){
- // count++;
- // }
- }
- return count;
- }
- }