Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 02-04-2008, 03:48 PM
Member
 
Join Date: Feb 2008
Posts: 3
divyachaparala is on a distinguished road
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
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 02-04-2008, 08:28 PM
tim's Avatar
tim tim is offline
Senior Member
 
Join Date: Dec 2007
Location: South Africa
Posts: 334
tim is on a distinguished road
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.
__________________
If your ship has not come in yet then build a lighthouse.

Last edited by tim : 02-04-2008 at 08:30 PM.
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 02-05-2008, 08:45 AM
Cnu Cnu is offline
Member
 
Join Date: Feb 2008
Posts: 13
Cnu is on a distinguished road
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
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 02-05-2008, 10:03 AM
Member
 
Join Date: Feb 2008
Posts: 3
divyachaparala is on a distinguished road
Quote:
Originally Posted by Cnu View Post
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.
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 02-05-2008, 10:21 AM
Member
 
Join Date: Jan 2008
Posts: 8
praveena is on a distinguished road
public class PerfectSquare{

public static void main(String args[]){

InputStream in= new InputStream(System.in);
int i,no;
boolean flag=false;
String str=in.readLine();
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
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Way to Java Perfect Javaisinmyblood New To Java 1 02-07-2008 12:28 AM
Help with code "perfect shuffle" trill New To Java 1 08-07-2007 08:25 AM


All times are GMT +3. The time now is 06:55 PM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org