没看过老毕写的,自己写了一个,比较垃圾,贡献出来,给大家交流一下
- package com.itheima;
- import java.util.ArrayList;
- /**
- * @author mishi
- *
- */
- public class Test2 {
- public static String getLettersNum(String str)
- {
- StringBuilder stringBuilder = new StringBuilder();
- char charNum='0';
- int num = 1;
- for(int i=0;i<str.length();i++)
- {
- charNum = str.charAt(i);
- if(charNum<65||charNum>122)
- continue;
- for(int j=i+1;j<str.length();j++)
- {
- if(charNum==str.charAt(j))
- num++;
- }
- stringBuilder.append(charNum);
- stringBuilder.append("(");
- stringBuilder.append(num);
- stringBuilder.append(")");
- num = 1;
- str =str.replace(charNum,'0');
- }
- return stringBuilder.toString();
-
- }
- /**
- * @param args
- */
- public static void main(String[] args) {
- // TODO 自动生成的方法存根
- System.out.println(getLettersNum("abcdekka27qoq"));
- }
- }
复制代码 |
|