|
C语言趣味程序百例精解之java实现(39)年龄几何
程序:
public class Test39{
public static void main(String args[]){
age39();
}
/**
* 39.年龄几何
*/
public static void age39() {
int a = 0, d = 0;
for (d = 1; d <= 6; d++)
for (a = 1; a <= 4; a++) {
if (a + a + d + a + 2 * d + a + 3 * d == 26
&& a * (a + d) * (a + 2 * d) * (a + 3 * d) == 880) {
System.out.println("a=" + a + " d=" + d);
for (int i = 0; i < 20; i++) {
System.out.println("s" + i + "=" + (a + d * i) + " a="
+ a + " d=" + d);
}
return;
}
}
}
}
运行:
C:\bat>java Test39
a=2 d=3
s0=2 a=2 d=3
s1=5 a=2 d=3
s2=8 a=2 d=3
s3=11 a=2 d=3
s4=14 a=2 d=3
s5=17 a=2 d=3
s6=20 a=2 d=3
s7=23 a=2 d=3
s8=26 a=2 d=3
s9=29 a=2 d=3
s10=32 a=2 d=3
s11=35 a=2 d=3
s12=38 a=2 d=3
s13=41 a=2 d=3
s14=44 a=2 d=3
s15=47 a=2 d=3
s16=50 a=2 d=3
s17=53 a=2 d=3
s18=56 a=2 d=3
s19=59 a=2 d=3 |
|