下列乘法算式中:每个汉字代表1个数字(1~9)。相同的汉字代表相同的数字,不同的汉字代表不同的数字。
赛软件 * 比赛 = 软件比拼
试编程确定使得整个算式成立的数字组合,如有多种情况,请给出所有可能的答案。
package java课程;
public class test01 {
public static void main(String[] args)
{
for(int x = 1;x<10;x++)
{
for(int y = 1;y<10;y++)
{
for(int z = 1;z<10;z++)
{
for(int w = 1;w<10;w++)
{
int a = 100*x+10*y+z;
int b = 10*w+x;
int c = a*b;
int d = c/1000;
int e = (c - d*1000)/100;
int f = (c-d*1000-e*100)/10;
if((d==y)&&(e==z)&&(f==w))
System.out.println(a + "*" + b + "=" + c);
}
}
}
}
}
}
运行结果:465*14=6510