SHARE
TWEET

Untitled

advictoriam Jan 15th, 2019 55 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public class Numbers
  2. {
  3.    /**
  4.       Counts the number of perfect squares in a given range
  5.       @param a the lower bound of the range
  6.       @param b the upper bound of the range
  7.       @return the number of perfect squares in the range [a,b] (including the bounds)
  8.    */
  9.    public int countPerfectSquares(int a, int b)
  10.    {
  11.       int count = 0;
  12.       for(int i = a; i <= b; i++)
  13.       {
  14.          if(Math.sqrt(i) == (int)Math.sqrt(i)){count++;}
  15.       }
  16.       return count;
  17.    }
  18. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top