请教大佬
求出三位数中,各位数字之和能被12整除的数,并统计其个数。 for i in range(100,1000):a = str(i)
b = list(a)
c = int(b)+int(b)+int(b)
if c%12 == 0:
print(i) j=0
for i in range(100,1000):
if i % 12 == 0:
print(i)
j+=1
print(j) 人家问的是Java{:10_277:} public class Test3 {
public static void main(String[] args) {
int num = 0;
for (int i = 100; i < 1000; i++) {
int geWei = i % 10;
int shiWei = i / 10 % 10;
int baiWei = i /100;
if ((geWei + baiWei + shiWei) % 12 == 0){
System.out.println(i);
num ++;
}
}
System.out.println("个数为:" + num);
}
}
页:
[1]