Quick actions

cmd+k|ctrl+k

Navigation

Languages

Triangular Triples

Snippet info

Language

Java

Visibility

public

Author

axelkalbach

Created

2017-02-26T17:33:46Z

Updated

2017-04-20T19:01:42Z

import java.util.ArrayList;
class Main {
    public static void main(String[] args) {
        System.out.println(triples(25L));
    }
    public static ArrayList triples(long h) {
        ArrayList<Integer> triples = new ArrayList<Integer>();
        int x = 1;
        long s = h * h;
        while(x < h) {
            double temp = s - x * x;
            //System.out.println("temp=" + temp);
            double a = Math.sqrt(temp);
            if (a % 1 == 0) {
                int y = (int) a;
                triples.add(x);
                triples.add(y);
            }
            // System.out.println("x=" + x);
            // System.out.println("a=" + a);
            x++;
        }
        return triples; 
    }
}
INFO