数字统计

import java.util.Scanner;

// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        // 注意 while 处理多个 case
            int a = in.nextInt();
            int b = in.nextInt();
           int i =a;
        int count=0;
        for(i=a;i<=b;i++){
            int x =i;
             while(x>0){
                if(x%10==2){
                    count++;
                }
                x/=10;
             }   
        }
        System.out.print(count);
    }
}

//import java.util.Scanner;

// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        // 注意 while 处理多个 case
            int a = in.nextInt();
            int b = in.nextInt();
           int i =a;
        int count=0;
        for(i=a;i<=b;i++){
            int x =i;
             while(x>0){
                if(x%10==2){
                    count++;
                }
                x/=10;
             }   
        }
        System.out.print(count);
    }
}

 

相关推荐

  1. henauOJ 1098: 数字统计

    2024-07-11 01:14:01       48 阅读
  2. [c]统计数字

    2024-07-11 01:14:01       69 阅读
  3. 统计单词数量(文件)(*)

    2024-07-11 01:14:01       38 阅读
  4. 扩展动态数据统计

    2024-07-11 01:14:01       35 阅读
  5. 统计商品各项数据sql&统计历史数据sql

    2024-07-11 01:14:01       66 阅读
  6. 数据结构练习——素数统计

    2024-07-11 01:14:01       55 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-07-11 01:14:01       114 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-07-11 01:14:01       124 阅读
  3. 在Django里面运行非项目文件

    2024-07-11 01:14:01       101 阅读
  4. Python语言-面向对象

    2024-07-11 01:14:01       112 阅读

热门阅读

  1. C编程题收藏

    2024-07-11 01:14:01       29 阅读
  2. 深入Django(六)

    2024-07-11 01:14:01       26 阅读
  3. django models对应的mysql类型

    2024-07-11 01:14:01       30 阅读
  4. Golang 输入与输出

    2024-07-11 01:14:01       28 阅读
  5. vue extend的作用和使用方法

    2024-07-11 01:14:01       26 阅读
  6. Android View滑动冲突解决方案

    2024-07-11 01:14:01       32 阅读
  7. 【Android】ADB 使用指南

    2024-07-11 01:14:01       33 阅读
  8. PHP语言教程与实战案例详解

    2024-07-11 01:14:01       30 阅读
  9. 【Spring Boot AOP中切入表达式格式介绍】

    2024-07-11 01:14:01       24 阅读