2个回答
展开全部
Scanner scanner = new Scanner(System.in);
String str = scanner.nextLine();//dasdascasd
char[] chars = str.toCharArray();
char c = 0;
int j = 1;
for (int i = 0; i < chars.length; i++) {
char b = chars[i];
if (c!=b) {
if (j!=1) {
System.out.print(j);
}
System.out.print(c);
j = 1;//初始化j
}else{
j = j + 1;
}
c = b;
}
System.out.println(chars[chars.length-1]);
}
String str = scanner.nextLine();//dasdascasd
char[] chars = str.toCharArray();
char c = 0;
int j = 1;
for (int i = 0; i < chars.length; i++) {
char b = chars[i];
if (c!=b) {
if (j!=1) {
System.out.print(j);
}
System.out.print(c);
j = 1;//初始化j
}else{
j = j + 1;
}
c = b;
}
System.out.println(chars[chars.length-1]);
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
String s="cdfffee";
char[] temp=s.toCharArray();
List<Character> list=new ArrayList<Character>();
for(char c:temp){
if(!list.contains(c)){
list.add(c);
}
}
StringBuffer strBuf=new StringBuffer();
for(int i=0,len=list.size();i<len;i++){
int count=0;
for(int j=0,leng=temp.length;j<leng;j++){
if(list.get(i).equals(temp[j])){
count++;
}
}
if(count!=0 && count!=1){
strBuf.append(count+list.get(i).toString());
}else{
strBuf.append(list.get(i).toString());
}
}
System.out.println(strBuf.toString());
char[] temp=s.toCharArray();
List<Character> list=new ArrayList<Character>();
for(char c:temp){
if(!list.contains(c)){
list.add(c);
}
}
StringBuffer strBuf=new StringBuffer();
for(int i=0,len=list.size();i<len;i++){
int count=0;
for(int j=0,leng=temp.length;j<leng;j++){
if(list.get(i).equals(temp[j])){
count++;
}
}
if(count!=0 && count!=1){
strBuf.append(count+list.get(i).toString());
}else{
strBuf.append(list.get(i).toString());
}
}
System.out.println(strBuf.toString());
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询