[Java] 验证费马大定理 →→→→→进入此内容的聊天室

来自 , 2020-10-19, 写在 Java, 查看 135 次.
URL http://www.code666.cn/view/8b0dc65f
  1. import java.util.Scanner;
  2.  
  3. public class CheckFermat {
  4.  
  5.         public static void checkFermat() {
  6.  
  7.                 Scanner in = new Scanner(System.in);
  8.                 System.out.print("请按顺序输入正整数a, b, c, n:");
  9.                 int a, b, c, n;
  10.                 a = in.nextInt();b = in.nextInt();c = in.nextInt();n = in.nextInt();
  11.  
  12.                 if(n > 0 && a > 0 && b > 0 && c > 0){
  13.                         if (n != 2 && (Math.pow(a, n) + Math.pow(b, n) == Math.pow(c, n))) {
  14.                                 System.out.println("老天,费马错了!");
  15.                         } else {
  16.                                 System.out.println("费马是对的~");
  17.                         }
  18.                 } else {
  19.                         System.out.println("输入错误, 请输入正整数!");
  20.                 }
  21.  
  22.                 System.out.print("是否继续测试(1/0): ");
  23.                 int d = in.nextInt();
  24.                 while (d != 0){
  25.                         checkFermat();
  26.                 }
  27.         }
  28.  
  29.         public static void main(String[] args) {
  30.                 System.out.println("程序开始运行!");
  31.                 checkFermat();
  32.                 System.out.println("程序运行结束!");
  33.     }
  34. }

回复 "验证费马大定理"

这儿你可以回复上面这条便签

captcha