Problem Statement :-
Write a Java program to check whether a given number is a perfect square or not
Condition :
Input will only be a positive interger and will not have any decimal or special characters
Input :
9
Output :
Perfect Square ? : TRUE
Code :
import java.util.*;
public class Solution3{
public static void main(String[] args) {
Scanner sc=new Scanner (System.in);
int n=sc.nextInt();
for(int i=0;i<n;i++){
int sqr=i*i;
if(sqr==n){
System.out.println("true");
}
}
}
}
Comments
Post a Comment