Hey guys, I'm trying to solve a problem I received in school. It states:
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 (a^n + b^n = c^n) holds. If n is greater than 2 and it turns out to be true that a^n + b^n = c^n, the program should print “Holy smokes,Fermat was wrong!” Otherwise the program should print “No, that doesn’t work.”
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.
I'm a little stumped on how I can use my method raiseToPow to help me solve checkFermat. Can someone explain to me how I might incorporate the two methods to find my answer? Right now I believe I can only calculate a + b = c. My code so far is below:
package fermat;
/**
*
* @author Josh
*/
public class Main {
public static void checkFermat (int a, int b, int c, int n) {
if (n <= 2) {
System.out.println ("Error: Enter a number larger than two");
return;
} else if (a + b == c ) {
System.out.println ("Holy smokes,Fermat was wrong!");
} else {
System.out.println ("Fermat was right!");
}}
public static int raiseToPow (int x, int n) {
double xn;
xn = Math.pow((double)x, (double)n);
return (int)xn;
}
public static void main(String[] args) {
// TODO code application logic here
checkFermat (3, 3, 3, 3);
raiseToPow (3, 3);
}
}