Translate

Sunday, June 5, 2016

Program to check whether a number is perfect square or not.

Asked by KPIT , BITWISE.


import java.util.Scanner;

class PerfectSquare
{
public static void main(String [] args)
{
Scanner s=new Scanner(System.in);

int number=s.nextInt();

double d=Math.sqrt(number);    // d for finding square root of number

int j=(int)d;   //  typecast d into intger

if(d-j==0)
{
System.out.println("Yes number is perfect square");
}
else
{
System.out.println(" number is not perfect square");
}
}
}


example-  entered number is 25 then o/p is  

No comments:

Post a Comment