我正在尝试用费马的最后一个方程制作一个递归分析程序,但它不断返回方程错误我不明白?
public class fermatdata
{
public static void data(int a, int b, int c, int n)
{
if ((Math.pow(a, n)) + (Math.pow(b, n)) == (Math.pow(c, n)))
{
System.out.println("Holy smokes, Fermat was wrong!");
return;
}
else
{
data(a-1, b-1, c-1, n-1);
if (n < 2)
{
return;
}
else
{
data(a-1, b-1, c-1, n-1);
}
}
System.out.println("No, that doesn't work. Fermat was right");
}
public static void main(String[] args)
{
System.out.println("Fermat's last theorem stated that the formula a^n + b^n = c^n while n>2 and all of the numbers are integers will never be correct. Here I am going to do an analysis with all the numbers starting at 100,000 and count backwords to 3");
data(100000, 100000, 100000, 100000);
}
}
尝试删除第一行,如下所示:
data(a-1, b-1, c-1, n-1);
好的,现在看看 Math.pow(100000,100000) 给出了什么(无穷大)。我认为问题在于您使用的值太高(至少对于 n 而言)。
我是一名优秀的程序员,十分优秀!