级数问题

题目描述
试计算在区间 11 到 nn的所有整数中,数字x(0 ≤ x ≤ 9)x(0≤x≤9)共出现了多少次?例如,在 11到1111中,即在 1,2,3,4,5,6,7,8,9,10,111,2,3,4,5,6,7,8,9,10,11 中,数字 11 出现了 44 次。

输入输出格式
输入格式:

22个整数n,xn,x,之间用一个空格隔开。

输出格式:

11个整数,表示xx出现的次数。

import java.util.Scanner;
 
public class Main {
    public void Breakup(int arr[], int n) {
        while(n!=0) {   
        arr[n%10]++;//个位取值
            n=n/10;//十位变个位
    }
    }
//public void Breakup(int arr[], int n) {思路正确 细节出错 这也是我发博客纪念这道题的原因
    //  String str = String.valueOf(n);
    //  for (int i = 0; i < str.length(); i++) {
    //      char c = str.charAt(i);
    //      String str2 = String.valueOf(c);
    //      int x = Integer.parseInt(str2);
    //      arr[x]++;
    //  }
    //}
    public static void main(String[] args) {// 测试用例
        Scanner sc = new Scanner(System.in);
        Main m = new Main();
        int x = sc.nextInt();
        int i = sc.nextInt();
        int arr[] = new int[10];
        for (int temp = 0; temp <= x; temp++) {
            m.Breakup(arr, temp);
        }
        System.out.println(arr[i]);
    }
}

转载于:https://www.cnblogs.com/cznczai/p/11149972.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值