Last active
May 21, 2021 14:06
-
-
Save bijay-shrestha/a40f5cc3c649221abfb026b4cc2f714d to your computer and use it in GitHub Desktop.
Check if the given number is a square of an integer
This file contains hidden or 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
package com.hawa.practice; | |
import lombok.extern.slf4j.Slf4j; | |
@Slf4j | |
public class IsSquare { | |
public static void main(String[] args) { | |
int number = 0; | |
log.info("Checking if {} has a square. Result: {}", number, isSquare(number)); | |
} | |
static int isSquare(int n) { | |
int isSquare = 0; | |
for (int i = 0; i <= n; i++) { | |
if (n == i * i) { | |
isSquare = 1; | |
break; | |
} | |
log.info("n {}", i); | |
} | |
return isSquare; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment