Skip to content

Instantly share code, notes, and snippets.

@caidanw
Created December 24, 2019 04:19
Show Gist options
  • Save caidanw/62e7777e9f67a5e24ff10224b8c3997b to your computer and use it in GitHub Desktop.
Save caidanw/62e7777e9f67a5e24ff10224b8c3997b to your computer and use it in GitHub Desktop.
public class PerfectSquare {
public static void main(String[] args) {
int min = 1;
int max = 10000;
int input = min + (int)(Math.random() * ((max - min) + 1));
if(isPerfectSquare(input)) {
System.out.println(input + " is a perfect square");
}
else {
System.out.println(input + " is not a perfect square");
}
}
static boolean isPerfectSquare(int num) {
int i = 1;
while (i * i < num) {
i += 1;
}
return i * i == num;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment