Last active
June 30, 2020 03:58
-
-
Save thmain/b46df68e6b01fefa1c5f4d841278666f 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 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