var str="abaasdffggghhjjkkgfddsssss"; //查出str中每个字母的个数,以及出现次数最多的字母次数var c=new Array();var i=0;while(str.charAt(0)){ c[i]=str.charAt(0)+'='+(str.split(str.charAt(0)).length-1); str=str.split(str.charAt(0)).join(''); i++;}alert(c);for(var j=0,m=0;j
var str="abc工"; /统计字节数var c=0;for(var i=0;i255) c+=2; else c++;}alert(c);
java版:
//java中没有像js中数组的join方法,split的算法也不一样,当只有一个或多个相同的字符时java中split后数组长度为0 public static void main(String[] args) throws Exception { String str="abbcccddddeaaaaaaaaaaaaaaaaaaaaafgbrekljgklwej"; Mapcount=new HashMap (26); for(int i=0;i
//转换¥public class TestString { private static final char[] data = new char[]{ '零','壹','贰','叁','肆','伍','陆','柒','捌','玖' }; private static final char[] units = new char[]{ '元','拾','佰','仟','万','拾','佰','仟','亿' }; public static void main(String[] args) { System.out.println(convert(123456789)); } public static String convert(int money) { if(money==0)return (data[0]+"")+units[0]; StringBuffer sb=new StringBuffer(); int unit=0; while(money!=0){ sb.insert(0, units[unit++]); int number=money%10; sb.insert(0, data[number]); money/=10; } return sb.toString(); }}