解题思路:
注意事项:
参考代码:
import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.List; import java.util.Scanner; import javax.swing.Box; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int min = scanner.nextInt();//最小范围 int max = scanner.nextInt();//最大范围 int sum = 0; for (int i = min; i <= max; i++) { int count = i; String box = Integer.toBinaryString(count);//转换为字符串遍历 for (int j = 0; j < box.length(); j++) { if (box.charAt(j)-48 == 1) { sum++; } } } System.out.println(sum); } }
0.0分
3 人评分