188k views
2 votes
Write a program to determine all pairs of positive integers, (a, b), such that a < b < 1000 and [a2 + b2 + 1)/(ab) is an integer.

1 Answer

1 vote

Answer:

1. We must import the packages for the array list

2. We create the array to store the data

3. We make the first for cycle for 1000 values

4. The second for cycle for the variable a

5. We make the operation

6. Cast the result to an Integer and check if they are equivalent

7. We print the result

Step-by-step explanation:

package javaapplication16;

import java.util.ArrayList;

public static void main(String[] args) {

ArrayList result = new ArrayList();

for(int b = 0; b < 1000; b++) {

for(int a = 0; a < b; a++) {

double calculatedResult = (Math.pow(a, 2) + Math.pow(b, 2) + 1) / (a * b);

if (calculatedResult == (int)calculatedResult) {

result.add("[" + a + "," + b + "]");

}

}

}

System.out.println("Result: " + result);

}

User Plap
by
4.5k points