java冒泡排序經(jīng)典代碼 java如何統(tǒng)計(jì)字符串中每個(gè)字符出現(xiàn)的次數(shù)?
java如何統(tǒng)計(jì)字符串中每個(gè)字符出現(xiàn)的次數(shù)?Public class test{Public static void main(string[]args){//指定字符和字符串char c=“1”st
java如何統(tǒng)計(jì)字符串中每個(gè)字符出現(xiàn)的次數(shù)?
Public class test{Public static void main(string[]args){//指定字符和字符串char c=“1”string string=“123456789111”系統(tǒng)輸出打印(getCharCount(c,string))}公共靜態(tài)int getCharCount(char c,string string){int count=0 for(int i=0 i<)字符串長度(一){字符溫度=字符串.charAt(i) If(C==temp)count}return count}
首先將字符串拆分為一個(gè)數(shù)組,然后使用map<string、int>對數(shù)字進(jìn)行計(jì)數(shù),然后打印