Congratulations to all the winners of April 2013, they have won INR 3400 cash and INR 20147 worth prizes !
DotNetFunda.Com Logo
Twitter TwitterLinkedIn
YouTubeGoogle
 Online : 29045 |  Welcome, Guest!   Register  Login
 Home > Code Snippets > Others > Write a program to find out whether the given number is a perfect square or not ...
Chikul

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

 Code Snippet posted by: Chikul | Posted on: 12/23/2009 | Category: Others Codes | Views: 7141 | Status: [Member] | Alert Moderator   


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");
}
}
}

Found interesting? Add this to:


>> Write Response - Respond to this post and get points

More codes snippets

About Us | Contact Us | The Team | Advertise | Software Development | Write for us | Testimonials | Privacy Policy | Terms of Use | Link Exchange | Members | Go Top
General Notice: If you find plagiarised (copied) contents on this page, please let us know the original source along with your correct email id (to communicate) for further action.
Copyright © DotNetFunda.Com. All Rights Reserved. Copying or mimicking the site design and layout is prohibited. Logos, company names used here if any are only for reference purposes and they may be respective owner's right or trademarks. | 5/18/2013 7:51:14 AM