呵呵,楼上的兄弟很会幽默
回复一个:
public class CharFrequency {
public String convert(String source) {
String target = "";
String first = "";
String temp = source;
int num=0;
while (temp.length() != 0) {
first = temp.substring(0, 1);
while (temp.indexOf(first) != -1) {
num++;
temp = temp.replaceFirst(first, "");
}
target += first + num;
num = 0;
}
return target;
}
public static void main(String[] args) {
CharFrequency test = new CharFrequency();
System.out.println(test.convert("aabbccabc"));
}
}
呵呵 二楼的很有意思啊!如果我输入bcdbcdbcd呢?难道要这样?
import java.io.*;
public class text{
BufferedReader input=null;
String string=null;
public void in(){
try{
input=new BufferedReader(new InputStreamReader(System.in));
string=input.readLine();
if(string.equals("bcdbcdbcd")){
System.out.println("b3c3a3");
}
}
catch(IOException e){
}
}
public static void main(String args[]){
text A=new text();
A.in();
}
}
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
public class Aa
{
public static void main(String arg[])throws IOException
{
String str;
int i,j=0,z=0;
int k=0;
char Array[]=new char[100];
BufferedReader buf=new BufferedReader(new InputStreamReader(System.in));
System.out.print("Input an integer:");
str=buf.readLine();
for(i=0;i<str.length();i++)
{
Array [i]=str.charAt(i);
}
for(i=0;i<=str.length();i++)
{
k=0;
z=0;
if(i==str.length())
{
break;
}
for(j=0;j<=str.length();j++)
{
if(Array[i]==Array[j])
k=k+1;
}
for(int n=0;n<=i;n++)
{
if(Array[i]==Array[n])
{
z++;
}
}
if(z==1)
{
System.out.print(Array[i]);
System.out.print(k);
}
}
}
}
小弟自己想的,用FOR来实现
[此贴子已经被作者于2007-8-8 21:37:06编辑过]