Write a program to find out whether the given number is a perfect square or not

Chikul
Posted by Chikul under Others category on | Views : 12358
For e.g.
Scenario 1: Input = 24 Output = 24 is not a perfect square
Scenario 2: Input = 25 Output = 25 is a perfect square of 5

import java.io.*;
import java.lang.*;

public class PerfectSquare
{
public static void main(String args[])throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter a String : ");
String s=br.readLine().toString();
double d=Double.parseDouble(s);
int i=(int)d;
double d1=Math.sqrt(d);
int j=(int)d1;
int k=j*j;
if(i==k)
{
System.out.println(s+" is a perfect Square");
}
else
{
System.out.println(s+" is not a perfect Square");
}
}
}

Comments or Responses

Login to post response