栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

Classic programming topic(经典的编程题)

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Classic programming topic(经典的编程题)

    题目:输入一行字符,分别统计出其中英文字母、空格、数字和其它字符的个数.
class Note{
  public class void main(String[] args){
        Scanner input = new Scanner(System.in);
        int alphabeticCount = 0;
        int spaceCount = 0;
        int digitCount = 0;
        int otherCount = 0;
        System.out.println("请输入:");
        String str = input.nextLine();
        char[] ch = str.toCharArray();
        for (int i = 0; i < ch.length; i++) {
            if (Character.isAlphabetic(ch[i])) {
                alphabeticCount++;
            } else if (Character.isSpaceChar(ch[i])) {
                spaceCount++;
            } else if (Character.isDigit(ch[i])) {
                digitCount++;
            } else {
                otherCount++;
            }
        }
        System.out.println("数字的个数:"+digitCount++);
        System.out.println("字母的个数:"+alphabeticCount++);
        System.out.println("空格的个数:"+spaceCount++);
        System.out.println("其它的个数:"+otherCount++);
    Scanner inputTwo =new Scanner(System.in);
 System.out.println("请输入数字:");
        int digit = input.nextInt();
        System.out.println("请输入相加几次:");
        int digitThree = input.nextInt();//几个数相加有键盘控制
        int sum=0;
        int sumTotal=0;
        for (int i = 0; i  
The results are as follows:
请输入:
今天天气真不错啊! The weather is really nice today!
数字的个数:0
字母的个数:35
空格的个数:6
其它的个数:2

请输入数字:
5
请输入相加几次:
5
61725

Process finished with exit code 0

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/731443.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号