Appear in Online Interview to test your skills and be ready for job!
Twitter Twitter LinkedIn YouTube Google
Be Interview ready ! | Search
Submit content and win cash & prizes monthly.
Winners

Win Prizes

Announcements
Like us on Facebook
Sponsor
Top Codes Author
Thu, 24-Apr-2014 Authors
All Time Authors
Satyapriyanayak
11600
Jayakumars
8120
Niladri.biswas
6000

Latest members | More ...


(Statistics delayed by 5 minutes)

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

Chikul
Posted by Chikul under Others on 12/23/2009 12:48:48 AM | Views : 8536 | Status : [Member]

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:



Comments or Responses


Login to post response.

Comments / Responses
Select text & click toolbar to format. Formatting appears in viewmode only. HTML Tags are not allowed.
Bold Italic Underline Paragraph Title Code  Link 
 Wait ... Processing ..... please wait.