fork(3) download
  1. class Ideone {
  2. public static void main (String[] args) throws java.lang.Exception {
  3. printPairs(4);
  4. }
  5.  
  6. private static void printPairs(int n) {
  7. for (int i = 1; i <= n; i++) {
  8. for (int j = 1; j <= n; j++) {
  9. long sum = (i * i) + (j * j);
  10. double root = Math.sqrt(sum);
  11. if (root == ((int) root)) {
  12. System.out.printf("Found pair (%d, %d): %d^2 + %d^2 = %d^2\n",
  13. i, j, i, j, (int) root);
  14. }
  15. }
  16. }
  17. }
  18. }
Success #stdin #stdout 0.05s 28084KB
stdin
Standard input is empty
stdout
Found pair (3, 4): 3^2 + 4^2 = 5^2
Found pair (4, 3): 4^2 + 3^2 = 5^2