阅读下列程序,写出程序运行的结果:
importjava.util.Scanner;
public class TestCharcount1{
public static void main(String []args){
int strNum=0;
int numNum=0;
int spcNum=0;
Scanner scanner=new Scanner(System.in);
System.out.print("请输入字符串:");
String str=scanner.nextLine(;
Character|]c=new Character[str.length0];
for(int i=0;i<str.length(;i++){
c[i]=str.charAt(1);
for(char j='0';j<='9';j++)
if(c[i]==j)
numNum++;
for(char j='a';j<='z';j+ +)
if(c[i].equals()))
strNum++;
for(char j='A';j<='Z';j++)
if(c[i].equals(j))
strNum++;
if(c[i].equals(''))
spcNum++;
}
System.out.println("strNum="+strNum);
System.out.printin("numNum="+numNum);
System.out.println("spcNum ="+spcNum);
/
}
输入字符串: I'm 22 years old in this year.
程序运行的结果:
(1)_______
(2)_____
(3)_________
import java.util.Scanner;
public class TestCharcount1 {
public static void main(String []args) {
int strNum = 0;
int numNum = 0;
int spcNum = 0;
Scanner scanner = new Scanner(System.in);
System.out.print("请输入字符串:");
String str = scanner.nextLine();
Character[] c = new Character[str.length()];
for(int i = 0; i < str.length(); i++) {
c[i] = str.charAt(i);
for(char j = '0'; j <= '9'; j++)
if(c[i] == j)
numNum++;
for(char j = 'a'; j <= 'z'; j++)
if(c[i] == j)
strNum++;
for(char j = 'A'; j <= 'Z'; j++)
if(c[i] == j)
strNum++;
if(Character.isWhitespace(c[i]))
spcNum++;
}
System.out.println("strNum=" + strNum);
System.out.println("numNum=" + numNum);
System.out.println("spcNum =" + spcNum);
}
}
输出:
strNum=21
numNum=2
spcNum=6