`

Java入门小练习---简单字符串统计

阅读更多
import java.util.Scanner;


public class StringTest {
	public static void main(String args[]){
		StringTest GUI=new StringTest();
		GUI.init();
	}

	public void init() {
		// TODO Auto-generated method stub
		Scanner scanner=new Scanner(System.in);
		String str=scanner.next();
		char[] test1=new char[str.length()];
		int[] test2=new int[128];
		int count=0;
		test1=str.toCharArray();
		for(int i=0;i<str.length();i++)
		{
			count=0;
			if(test2[(int)test1[i]]==1)
			{
				i++;
			}
			else
			{
				test2[(int)test1[i]]=1;
				for(int j=i+1;j<str.length();j++)
				{
					if(test1[i]==test1[j])
					{
						count++;
					}
				}
				{System.out.println(test1[i]+"出现的次数为:"+(count+1));}
			}
		}
	}
}

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics