import java.util.Scanner; public class CheckFermat { public static void checkFermat() { Scanner in = new Scanner(System.in); System.out.print("请按顺序输入正整数a, b, c, n:"); int a, b, c, n; a = in.nextInt();b = in.nextInt();c = in.nextInt();n = in.nextInt(); if(n > 0 && a > 0 && b > 0 && c > 0){ if (n != 2 && (Math.pow(a, n) + Math.pow(b, n) == Math.pow(c, n))) { System.out.println("老天,费马错了!"); } else { System.out.println("费马是对的~"); } } else { System.out.println("输入错误, 请输入正整数!"); } System.out.print("是否继续测试(1/0): "); int d = in.nextInt(); while (d != 0){ checkFermat(); } } public static void main(String[] args) { System.out.println("程序开始运行!"); checkFermat(); System.out.println("程序运行结束!"); } }