Ask Question
2 January, 17:23

Write a boolean method that checks whether a given positive integer n is a perfect square. Use Math's sqrt and round methods to find the square root of n, round it, then square the result and compare with n. Do not use any iterations or recursion.

+2
Answers (1)
  1. 2 January, 20:39
    0
    In java ...

    public boolean checkSquare (int n) {

    int actualNumber = n;

    int squareRoot = (int) Math. sqrt (n);

    int squaredNumber = Math. pow (squareRoot, 2);

    if (squaredNumber==actualNumber) {

    return true;

    } else {

    return false;

    }

    }
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “Write a boolean method that checks whether a given positive integer n is a perfect square. Use Math's sqrt and round methods to find the ...” 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