小题一道,测试编程能力
提示: 作者被禁止或删除 内容自动屏蔽
public class OneCounter { public static int counter(int n) { int count = 0; StringBuilder buffer = new StringBuilder(); for (int i = 0; i <= n; ++i) buffer.append(i); for (int i = 0; i < buffer.length(); ++i) if (buffer.charAt(i) == '1') ++count; return count; } public static void main(String[] args) { System.out.println(counter(13)); System.out.println(counter(133)); System.out.println(counter(90)); } }