Ask Question
6 March, 10:50

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.

+4
Answers (1)
  1. 6 March, 14:16
    0
    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

    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);

    }
Know the Answer?
Not Sure About the Answer?
Get an answer to your question ✅ “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. ...” in 📙 Computers & Technology if there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers