Ask Question
23 August, 14:03

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.

+5
Answers (1)
  1. 23 August, 14:14
    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 & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers