作业帮 > 综合 > 作业

编程1~1000之间(包括1和1000在内)有多少个整数的各位数字之和小于7

来源:学生作业帮 编辑:搜搜考试网作业帮 分类:综合作业 时间:2024/08/19 02:52:51
编程1~1000之间(包括1和1000在内)有多少个整数的各位数字之和小于7
编程1~1000之间(包括1和1000在内)有多少个整数的各位数字之和小于7
public static void main(String[] args) {
  int start = 0;
  int end = 100;
  for (int i = start; i <= end; i++) {
   String temp = String.valueOf(i);
   char[] tempChar = temp.toCharArray();
   int result = 0;
   for (int j = 0; j < tempChar.length; j++) {
    result += new Integer(tempChar[j] - 48);
   }
   if (result < 7)
    System.out.println("数字" + i + "各位数字的和为:" + result);
  }
 }