62,614
社区成员
发帖
与我相关
我的任务
分享
public class StringCaculate
{
private int i,j,k,l;
public StringCaculate
{
i=0;j=0;k=0;l=0;
}
public void caculate(String o)
{
StringBuffer aBuffer=new StringBuffer(o.lengh());
char aCharacter;
for(int m=0;m<o.lengh();m++)
{
aCharacter=o.charAt(i);
if(Character.isLetter(aCharacter))
i++;
else if(Character.isDigit(aCharacter))
j++;
else
l++;
}
System.out.println("有字母"+i+"个");
System.out.println("有数字"+j+"个");
System.out.println("有空格"+l+"个");
}
}
public class test
{
public static void main(String[] args)
{
String a="this is a string";
StringCaculate.caculate(a);
}
}
StringCaculate sc = new StringCaculate();
sc.caculate("abc");
sc.caculate("abc");
sc.caculate("abc");
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package exp1;
/**
*
* @author 364
*/
public class StringCaculate
{
private int i,j,k,l;
public StringCaculate()
{
i=0;j=0;k=0;l=0;
}
public void caculate(String o)
{
StringBuffer aBuffer=new StringBuffer(o.length());
char aCharacter;
for(int m=0;m<o.length();m++)
{
aCharacter=o.charAt(m);
if(Character.isLetter(aCharacter))
i++;
else if(Character.isDigit(aCharacter))
j++;
else
l++;
}
System.out.println("有字母"+i+"个");
System.out.println("有数字"+j+"个");
System.out.println("有空格"+l+"个");
}
}
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package exp1;
/**
*
* @author bobo364
*/
class test
{
public static void main(String[] args)
{
String a="this is a string";
StringCaculate c=new StringCaculate();
c.caculate(a);
}
}
public static void testCount(String str) {
char[] array = str.toCharArray();
int letter = 0, number = 0, space = 0;
for (int i = 0; i < array.length; i++) {
if (array[i] == ' ')
space++;
else if (array[i] >= '0' && array[i] <= '9')
number++;
else if (array[i] >= 'a' && array[i] <= 'z')
letter++;
}
System.out.println("space=" + space + " number=" + number + " letter="
+ letter);
}