字符个数统计的方法详解(java)

字符个数统计的方法详解(java)

2023年7月25日发(作者:)

字符个数统计的⽅法详解(java)编写⼀个函数,计算字符串中含有的不同字符的个数。字符在 ASCII 码范围内( 0~127 ,包括 0 和 127 ),换⾏表⽰结束符,不算在字符⾥。不在范围内的不作统计。多个相同的字符只计算⼀次⽅法⼀:在这⾥插⼊代码⽚import .*public class Main{public statci void main(String[ ] args) throws IOExce{ InputStream in = ; int av = ble(); int num = 0; char[] chars = new char[av]; while(av-->0){ chars[ av] =(char)(); } StringBuilder sb = new StringBuilder(); for(int i =0;i<;i++){ if(chars[i]=='n'){ contiue;//换⾏符不算在字符个数中 } if((chars[i]>-1&&char[i]<128)&&(dexOf(f(chars[i]))!=-1){ (chars[i]); num++;

}

} n(num);}}⽅法⼆:在这⾥插⼊代码⽚ public static void main(String[]args)throws Exception{ BufferedReader br= new BufferedReader(new InputStreamReader()); String s = ne(); int[] arr = new int[128]; int count=0; for(int i=0;i<();i++){ char b = (i); if(arr[b]==0){ count++; arr[b]=1; } } n(count); }

发布者:admin,转转请注明出处:http://www.yc00.com/web/1690230179a318200.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信