Search
Sponsor
Winners

Win Prizes

Social Presence
Twitter Twitter LinkedIn YouTube Google

Like us on Facebook
Advertisements
Top Codes Author
Tue, 30-Sep-2014 Authors
Vishal@Neeraj
480
Bandi
400
All Time Authors
Satyapriyanayak
12160
Jayakumars
8120
Vishal@Neeraj
6480

Latest members | More ...


(Statistics delayed by 5 minutes)
 Codes

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 : 9216 | 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