Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Numbers
- {
- /**
- Counts the number of perfect squares in a given range
- @param a the lower bound of the range
- @param b the upper bound of the range
- @return the number of perfect squares in the range [a,b] (including the bounds)
- */
- public int countPerfectSquares(int a, int b)
- {
- int count = 0;
- for(int i = a; i <= b; i++)
- {
- if(Math.sqrt(i) == (int)Math.sqrt(i)){count++;}
- }
- return count;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement