LanQiaoTestCodes/门牌制作.java

23 lines
637 B
Java
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package LanQiaoOJ;
/*
* 小蓝要为一条街的住户制作门牌号。
这条街一共有 2020 位住户,门牌号从 1 到 2020 编号。
小蓝制作门牌的方法是先制作 0 到 9 这几个数字字符,最后根据需要将字符粘贴到门牌上,
例如门牌 1017 需要依次粘贴字符1、0、1、7即需要
1 个字符 02 个字符 11 个字符 7
请问要制作所有的 1 到 2020 号门牌,总共需要多少个字符 2*/
public class 门牌制作 {
public static void main(String[] args) {
int count=0;
for(int i=1;i<=2020;i++) {
String numStr=Integer.toString(i);
for(int j=0;j<numStr.length();j++) {
if(numStr.charAt(j)=='2')
count++;
}
}
System.out.print(count);
}
}