Advertisement
Guest User

PythagoreanNumbers

a guest
Sep 18th, 2014
237
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3.  
  4. public class PythagoreanNumbers {
  5.  
  6. public static void main(String[] args) {
  7.  
  8. Scanner input = new Scanner(System.in);
  9. int n = input.nextInt();
  10. int[] numbers = new int [n];
  11. int count = 0;
  12.  
  13. // input
  14. for (int i = 0; i < n; i++) {
  15.  
  16. numbers[i] = input.nextInt();
  17. }
  18.  
  19. // calculation
  20.  
  21. for (int i1 = 0; i1 < numbers.length; i1++) {
  22.  
  23. for (int i2 = i1; i2 < numbers.length; i2++) {
  24.  
  25. for (int i3 = 0; i3 < numbers.length; i3++) {
  26.  
  27. if ( (Math.pow(numbers[i1], 2) + Math.pow(numbers[i2], 2) == Math.pow(numbers[i3], 2)) ) {
  28.  
  29. System.out.printf("%1$d*%1$d + %2$d*%2$d = %3$d*%3$d\n", numbers[i1], numbers[i2], numbers[i3]);
  30. count++;
  31. } else {
  32.  
  33. continue;
  34. }
  35.  
  36. }
  37. }
  38. }
  39. if (count == 0) {
  40. System.out.println("No");
  41. }
  42. }
  43.  
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement