Guest User

Untitled

a guest
Feb 20th, 2019
325
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.09 KB | None | 0 0
  1.     package Thirteen;
  2.  
  3.     import java.math.BigInteger;
  4.  
  5.     public class Thirteen implements Runnable {
  6.     private BigInteger p, q, r;
  7.  
  8.     public Thirteen(BigInteger p, BigInteger q, BigInteger r) {
  9.         this.p = p;
  10.         this.q = q;
  11.         this.r = r;
  12.     }
  13.     private BigInteger calculatePSquare() {
  14.         return p.pow(2);
  15.     }
  16.     private BigInteger calculate3TimesPQ() {
  17.         return p.multiply(BigInteger.ONE.add(BigInteger.TWO)).multiply(q);
  18.     }
  19.     private BigInteger calculateQSquare() {
  20.         return q.pow(2);
  21.     }
  22.     private BigInteger calculateRSquare() {
  23.         return r.pow(2);
  24.     }
  25.     public boolean calculateEquation() {
  26.         //Equation: p² + 3pq + q² = r²
  27.         if (calculatePSquare().add(calculate3TimesPQ()).add(calculateQSquare()).equals(calculateRSquare())) {
  28.             System.out.println("p: " + p + " q: " + q + " r: " + r);
  29.         }
  30.         return calculatePSquare().add(calculate3TimesPQ()).add(calculateQSquare()).equals(calculateRSquare());
  31.     }
  32.     @Override
  33.     public void run() {
  34.         calculateEquation();
  35.     }
  36.     }
Add Comment
Please, Sign In to add comment