Topic: 求一道JAVA题算法 |
Print this page |
1.求一道JAVA题算法 | Copy to clipboard |
Posted by: 婴孩 Posted on: 2007-11-07 11:48 随意打出一串字符,设计程序判断这些字符中有几个是 字母,数字, 空格,及其他符号,并输出。 |
2.Re:求一道JAVA题算法 [Re: 婴孩] | Copy to clipboard |
Posted by: xuxiaolei Posted on: 2007-11-07 12:15 问题你已经说的很明白了,自己解决吧,很简单噢 |
3.Re:求一道JAVA题算法 [Re: 婴孩] | Copy to clipboard |
Posted by: xuxiaolei Posted on: 2007-11-07 12:17 问题你已经说的很明白了,自己解决吧,很简单噢 |
4.Re:求一道JAVA题算法 [Re: 婴孩] | Copy to clipboard |
Posted by: long_5281 Posted on: 2007-11-08 13:38 static int cCount = 0 ; //字符统计 static int nCount = 0 ; //数字统计 static int sCount = 0 ; //空格统计 static int oCount = 0 ; //其他符号统计 public static void main(String[] args){ String msg = "what'%91 @ name " ; byte[] chars = msg.getBytes(); if(chars!=null){ for(byte c:chars){ if(c==32){ sCount++; }else if(c>=65&&c<=122){ cCount++; }else if(c>=48&&c<=57){ nCount++; }else{ oCount++; } } } System.out.println("该字符串"+msg+"中,字符数["+cCount+"]、数字数["+nCount+"]、空格数["+sCount+"]、其他符号数["+oCount+"]"); } |
Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1 客服电话 18559299278 客服信箱 714923@qq.com 客服QQ 714923 |