简单的java程序问题。
importjava.util.*;publicclasssushu{publicstaticvoidmain(String[]args){intabccount=0;i...
import java.util.*;
public class sushu
{
public static void main(String[] args)
{
int abccount=0;
int spacecount=0;
int numcount=0;
int othercount=0;
Scanner scan=new Scanner(System.in);
String str=scan.nextLine();
char[] ch=str.toCharArray();
for(int i=0;i<ch.length;i++)
{
if(Character.isLetter(ch[i])){abccount++;}
else if(Character.isDigit(ch[i])){numcount++;}
else if(Character.isSpaceChar(ch[i])){spacecount++;}
else{othercount++;}
}
System.out.println("字母个数:"+abccount);
System.out.println("数字个数:"+numcount);
System.out.println("空格个数:"+spacecount);
System.out.println("其他字符个数:"+othercount);
}
} 展开
public class sushu
{
public static void main(String[] args)
{
int abccount=0;
int spacecount=0;
int numcount=0;
int othercount=0;
Scanner scan=new Scanner(System.in);
String str=scan.nextLine();
char[] ch=str.toCharArray();
for(int i=0;i<ch.length;i++)
{
if(Character.isLetter(ch[i])){abccount++;}
else if(Character.isDigit(ch[i])){numcount++;}
else if(Character.isSpaceChar(ch[i])){spacecount++;}
else{othercount++;}
}
System.out.println("字母个数:"+abccount);
System.out.println("数字个数:"+numcount);
System.out.println("空格个数:"+spacecount);
System.out.println("其他字符个数:"+othercount);
}
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询