Advertisement
advictoriam

Untitled

Jan 15th, 2019
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.48 KB | None | 0 0
  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. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement