问题补充:Elipse下运行没错,dos下运行会出警告:编码GBK的不可映射字符.且无法运行!/*求所有满足等式AB+CD=DC的所有A,B,C,D,且A,B,C,D必须为一位的自然数(A,B,C,D不能为0)
执行结果提示:
18+13=31
18+24=42
...
72+19=91*/
public class Alone4_9
{
public static void main(String[] args)
{
for(int A=1;A<=9;A++)
for(int B=1;B<=9;B++)
for(int C=1;C<=9;C++)
for(int D=1;D<=9;D++)
{
if(A*10+B+C*10+D==D*10+C)
System.out.println(A+B+"+"+C+D+"="+D+C);
}
}
}
执行结果提示:
18+13=31
18+24=42
...
72+19=91*/
public class Alone4_9
{
public static void main(String[] args)
{
for(int A=1;A<=9;A++)
for(int B=1;B<=9;B++)
for(int C=1;C<=9;C++)
for(int D=1;D<=9;D++)
{
if(A*10+B+C*10+D==D*10+C)
System.out.println(A+B+"+"+C+D+"="+D+C);
}
}
}
是不是你的环境有问题?你的dos加载中文了?C:\>java Alone4_9
9+13=31
9+24=42
9+35=53
9+46=64
9+57=75
9+68=86
9+79=97
9+14=41
9+25=52
9+36=63
9+47=74
9+58=85
9+69=96
9+15=51
9+26=62
9+37=73
9+48=84
9+59=95
9+16=61
9+27=72
9+38=83
9+49=94
9+17=71
9+28=82
9+39=93
9+18=81
9+29=92
9+19=91