Ask 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 square root of n, round it, then square the result and compare with n. Do not use any iterations or recursion.

+1
Answers (1)
  1. 30 June, 09:06
    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 & 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