Created
December 24, 2019 04:19
-
-
Save caidanw/62e7777e9f67a5e24ff10224b8c3997b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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