Skip to content

Instantly share code, notes, and snippets.

@bijay-shrestha
Last active May 21, 2021 14:06
Show Gist options
  • Save bijay-shrestha/a40f5cc3c649221abfb026b4cc2f714d to your computer and use it in GitHub Desktop.
Save bijay-shrestha/a40f5cc3c649221abfb026b4cc2f714d to your computer and use it in GitHub Desktop.
Check if the given number is a square of an integer
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