1. Member
Join Date
Feb 2008
Posts
3
Rep Power
0

## Perfect Squares

Hi All,

Am new to java and i got a assignment on perfect squares can please help me how to do that... but not by using Math.Sqrt all these methods.. Please help me atleast give some ideas....

Thanks

2. ## Welcome to the forums!

Hello divyachaparala.

Your question is a bit vague. Are you looking for all the perfect squares up to some integer? Please ask your question clearly and explain what is expected for your assignment. ;)
Last edited by tim; 02-04-2008 at 08:30 PM.

3. Member
Join Date
Feb 2008
Posts
13
Rep Power
0
import java.util.*;
class PerfectSquares
{
public static void main(String[] args)
{
Scanner s=new Scanner(System.in);
int n=s.nextInt();
int i=1;
while(i<=n)
{
System.out.println("Square of"+i+"is"+i*i);
i++;
}//end of while
}//end of main()
}//end of class

4. Member
Join Date
Feb 2008
Posts
3
Rep Power
0
Originally Posted by Cnu
import java.util.*;
class PerfectSquares
{
public static void main(String[] args)
{
Scanner s=new Scanner(System.in);
int n=s.nextInt();
int i=1;
while(i<=n)
{
System.out.println("Square of"+i+"is"+i*i);
i++;
}//end of while
}//end of main()
}//end of class

hi
sorry this is not i want...

if we give a number it should tell us weather its a perfect square are not....
Thanks.

5. Member
Join Date
Jan 2008
Posts
8
Rep Power
0
public class PerfectSquare{

public static void main(String args[]){

InputStream in= new InputStream(System.in);
int i,no;
boolean flag=false;
no=Integer.parseInt(str);
for(i=0;i<no/2;i++)
{
if(i*i==no)
{
System.out.println("The no is a perfect square..");
flag=true;
break;

}//if
}//for
if(!flag)
System.out.println("The no is not perfect square..");
}//main
}//class

You can also use the basic principle of perfect squares..

Only perfect squares have odd no of factors..

Eg: factors(25)= 1,5,25

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•