an+bn = cn
except in the case when n = 2.
Write a method named checkFermat that takes four integers as parameters—a, b, c and n—and that checks to see if Fermat’s theorem holds. If n is greater than 2 and it turns out to be true that an+bn = cn, the program should print than 2 and it turns out to be true that an+bn = cn, the program should print
You should assume that there is a method named raiseToPow that takes two integers as arguments and that raises the first argument to the power of the second. For example:
int x = raiseToPow(2,3);
would assign the value 8 to x, because 23 = 8.
public class C4E5 {
ReplyDeletepublic static void checkFermat(int a,int b,int c,int n) {
if (n>2&&(Math.pow(a, n)+(Math.pow(b, n))==(Math.pow(c, n)))){
System.out.println("Holy smokes, Fermat was wrong!");
}else {
System.out.println("No, that doesn't work");
}
}
public static void main (String[] args) {
checkFermat(3,4,5,2);
}
}