svetlozar_kirkov

Pythagorean Numbers

Feb 6th, 2015
319
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.12 KB | None | 0 0
  1. import java.util.ArrayList;
  2. import java.util.Scanner;
  3.  
  4. public class PythagoreanNumbers {
  5.  
  6.     public static void main(String[] args) {
  7.         Scanner input = new Scanner(System.in);
  8.         int n = input.nextInt();
  9.         ArrayList<Integer> numbers = new ArrayList<>();
  10.         for (int i = 0; i < n; i++){
  11.             numbers.add(input.nextInt());
  12.         }
  13.         boolean found = false;
  14.         for (int i = 0; i < n; i++){
  15.             for (int j = 0; j < n; j++){
  16.                 for (int k = 0; k < n; k++){
  17.                     int numOne = numbers.get(i);
  18.                     int numTwo = numbers.get(j);
  19.                     int numThree = numbers.get(k);
  20.                     if (numOne <= numTwo && (numOne*numOne)+(numTwo*numTwo)==numThree*numThree){
  21.                         System.out.printf("%d*%d + %d*%d = %d*%d\n",
  22.                                 numOne,numOne,numTwo,numTwo,numThree,numThree);
  23.                         found = true;
  24.                     }
  25.                 }
  26.             }
  27.         }
  28.         if (found == false){
  29.             System.out.println("No");
  30.             return;
  31.         }
  32.     }  
  33. }
Advertisement
Add Comment
Please, Sign In to add comment