Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.math.BigInteger;
- public class BigPythagoras {
- /**
- * Program: BigPythagoras.java
- * Purpose: List of right-angled triangles whose sides are integers
- * Creator: Chris Clarke
- * Created: 20.07.2014
- */
- public static void main(String[] args) {
- BigInteger a = new BigInteger("3");
- System.out.println("List of right-angled triangles whose sides are integers");
- System.out.println("a^2 + b^2 = c^2");
- System.out.println("===============");
- for (int i=0; i<12; i++) {
- a = calcSides(a);
- } // end while
- } // end main()
- public static BigInteger calcSides(BigInteger a) {
- // given a, calculate b and c and display all 3 values
- /*
- Pythagoras' Theorem states that:
- "In a right-angled triangle, the square on the hypotenuse is equal
- to the sum of the squares on the other two sides."
- a^2 + b^2 = c^2, where a, b and c are sides of a right-angled triangle,
- and c is the hypotenuse.
- */
- // b = ((a * a)-1)/2
- BigInteger b = (a.multiply( a).subtract( BigInteger.ONE)).divide(new BigInteger("2"));
- BigInteger c = b.add(BigInteger.ONE);
- // print sides of right-angled triangle
- System.out.println(a+", "+b+", "+c);
- return c; // will become argument for next function call
- } // end calcSides()
- } // end class BigPythagoras
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement