-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheckForWholeSquare.java
More file actions
33 lines (28 loc) · 1011 Bytes
/
checkForWholeSquare.java
File metadata and controls
33 lines (28 loc) · 1011 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
// you can also use imports, for example:
// import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
import java.util.*;
import java.lang.Math;
class Solution {
public int solution(int A, int B) {
int firstNumber = A;
int secondNumber = B;
int range = (secondNumber - firstNumber) + 1;
int[] listOfNumbers = new int[range];
int numberOfWholeSquares = 0;
for (int i = 0; i < range; i++) {
listOfNumbers[i] = firstNumber;
firstNumber++;
}
for (int i = 0; i < listOfNumbers.length; i++) {
if ((listOfNumbers[i] % Math.sqrt(listOfNumbers[i])) == 0) {
numberOfWholeSquares++;
}
}
// for (int i = 0; i < listOfNumbers.length; i++) {
// System.out.println(listOfNumbers[i]);
// }
return numberOfWholeSquares;
}
}