Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class PythagoreanNumbers {
- public static void main(String[] args) {
- Scanner input = new Scanner(System.in);
- int n = input.nextInt();
- int[] numbers = new int [n];
- int count = 0;
- // input
- for (int i = 0; i < n; i++) {
- numbers[i] = input.nextInt();
- }
- // calculation
- for (int i1 = 0; i1 < numbers.length; i1++) {
- for (int i2 = i1; i2 < numbers.length; i2++) {
- for (int i3 = 0; i3 < numbers.length; i3++) {
- if ( (Math.pow(numbers[i1], 2) + Math.pow(numbers[i2], 2) == Math.pow(numbers[i3], 2)) ) {
- System.out.printf("%1$d*%1$d + %2$d*%2$d = %3$d*%3$d\n", numbers[i1], numbers[i2], numbers[i3]);
- count++;
- } else {
- continue;
- }
- }
- }
- }
- if (count == 0) {
- System.out.println("No");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement