Ask Question
19 November, 06:36

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.

+3
Answers (1)
  1. 19 November, 09:45
    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?
Find 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 and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers