- package my.test;
- /*
- * Hello12345World
- * 大写 : 2个
- * 小写 : 8个
- * 数字 : 5个
- */
- public class Test {
- public static void main(String[] args) {
- String st = "Hello12345World";
- int ucount = 0, lcount = 0, num = 0;
- char[] ch = st.toCharArray();
- for (int i = 0; i < ch.length; i++) {
- (ch[i]<58?num:(ch[i]<98?ucount:lcount))+=1;//之前用的if语句可以,想着用三元运算符就不行了
- }
- System.out.println(ucount+"***"+lcount+"***"+num);
-
- }
- }
复制代码 |