Skip to content

Instantly share code, notes, and snippets.

@thmain
Last active June 30, 2020 03:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thmain/b46df68e6b01fefa1c5f4d841278666f to your computer and use it in GitHub Desktop.
Save thmain/b46df68e6b01fefa1c5f4d841278666f to your computer and use it in GitHub Desktop.
public class ValidateSquare {
public static boolean isSquare(int n){
if(n==0 || n==1)
return true;
for (int i = 0; i <=n/2 ; i++) {
int x = i*i;
if(x==n)
return true;
else if (n<x)
return false;
else
continue;
}
return false;
}
public static void main(String[] args) {
int n = 37;
System.out.println(n + " is square: " + isSquare(n));
n = 49;
System.out.println(n + " is square: " + isSquare(n));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment