-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFermat.java
More file actions
33 lines (28 loc) · 1.19 KB
/
Fermat.java
File metadata and controls
33 lines (28 loc) · 1.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
//Exercise 5.3
import java.util.Scanner;
public class Fermat {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
System.out.println("Fermat's Last Theorem says that there are no integers a, b, c, and n such that an + bn = cn, except when n is equal to or smaller than 2. Let's check if he's actually right!");
int a, b, c, n;
System.out.println("Please enter an integer for a.");
a = in.nextInt();
System.out.println("Please enter an integer for b.");
b = in.nextInt();
System.out.println("Please enter an integer for c.");
c = in.nextInt();
System.out.println("Please enter an integer for n.");
n = in.nextInt();
double left = Math.pow(a, n) + Math.pow(b, n);
double right = Math.pow(c, n);
if (left != right) {
System.out.println("No, that doesn't work.");
} else {
if (n > 2) {
System.out.println("Holy smokes, Fermat was wrong!");
} else {
System.out.println("The equation stands but this agrees with Fermat's Last Theorem!");
}
}
}
}