1,2,3,4,5,6,10,11,12,13,14,15,20,21,22,23,24,30,31,32,33,40,41,42,50,51,60,100,101,102,103,104,105,110,111,112,113,114,120,121,122,123,130,131,132,140,141,150,200,201,202,203,204,210,211,212,213,220,221,222,230,231,240,300,301,302,303,310,311,312,320,321,400,401,402,410,411,420,500,501,510,600,1000。 总共83个。
public static void main(String arg[])
{
int sum = 0;
int mun =0;
for(int i = 1;i<1001;i++){
sum = i/1000+(i%1000)/100+(i%100)/10+(i%10);
if(sun<7)
{
System.out.print(sun);
mun++;
}
}
system.out.println("一共有:"+num+"个字符合要求");
}
语法有可能不正确。思路应该没问题。就是把这个数除以1000~10取每一位的值相加判断是不是小于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);
}
}