文章标题

    xiaoxiao2021-04-19  179

    输入一行字符,分别统计出其中英文字母、空格、数字和其它字符的个数

    import java.util.*; public class Test5{ public static void main(String[] args){ char[] ch = null; int Figure = 0,English=0,Space=0,Else=0; System.out.print("输入一行字符:"); Scanner in = new Scanner(System.in); String str = in.nextLine(); ch = str.toCharArray(); int count = ch.length; for(int i = 0;i<count;i++){ if(ch[i]>='0'&&ch[i]<='9') Figure++; else if(ch[i]>='a'&&ch[i]<='z' || ch[i]>='A'&&ch[i]<='Z') English++; else if(ch[i]==' ') Space++; else Else++; } System.out.println("English:"+English+"; Figure:"+Figure+"; Space:"+Space+"; Else:"+Else+"."); } }
    转载请注明原文地址: https://ju.6miu.com/read-676169.html

    最新回复(0)