Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old May 15th, 2005, 12:30 PM   #11
xavier
Professional Programmer
 
xavier's Avatar
 
Join Date: Oct 2004
Location: .ro
Posts: 381
Rep Power: 4 xavier is on a distinguished road
Send a message via Yahoo to xavier
I'll try:
First let's say the user inputs a number : n witch is the area. Now you should see if Math.sqrt(n) is an integer. If it is an integer, then you hava on your hands a square.
Lets say int a = Math.sqrt(n); a will be one of the dimensions => Perimeter = a*4; Dimension = a;

The important part is to test wether Math.sqrt(n) is an integer or not. But you can google a bit for that one, cause it's not that hard.

Now , if Math.sqrt(n) is not an integer then the area is that of a rectangle. You have to find a and b , witch is length and width. Lets say n=12; you could find all its divisors, and see wich of them multiplied equals 12. Like : 3*4, 2*6, 1*12. I don't now if you have to get all the posibilities or only one. The perimeter = a+b.

That's just to get you started , hope u understood... so ... next time come with some code
__________________
Don't take life too seriously, it's not permanent !

Last edited by xavier; May 15th, 2005 at 12:33 PM.
xavier is offline   Reply With Quote
Old May 15th, 2005, 4:10 PM   #12
JDStud6
Programmer
 
Join Date: Jan 2005
Location: Charleston, SC www.wareonearth.com
Posts: 57
Rep Power: 4 JDStud6 is on a distinguished road
Send a message via AIM to JDStud6
rectangle perimeter is actually 2*(a+b)

JD
JDStud6 is offline   Reply With Quote
Old May 15th, 2005, 4:30 PM   #13
ZenMasterJG
Hobbyist Programmer
 
ZenMasterJG's Avatar
 
Join Date: Nov 2004
Location: Boston, MA
Posts: 148
Rep Power: 4 ZenMasterJG is on a distinguished road
Send a message via AIM to ZenMasterJG
If i remember my math classes right, and i occasionally do, the optimum area for a miniumum dimensions will always be a sqare, not a rectangle. so you luck out. i think.
ZenMasterJG is offline   Reply With Quote
Old May 15th, 2005, 6:56 PM   #14
Dark Flare Knight
Hobbyist Programmer
 
Join Date: Mar 2005
Location: Canada
Posts: 113
Rep Power: 4 Dark Flare Knight is on a distinguished road
Quote:
Originally Posted by xavier
I'll try:
First let's say the user inputs a number : n witch is the area. Now you should see if Math.sqrt(n) is an integer. If it is an integer, then you hava on your hands a square.
Lets say int a = Math.sqrt(n); a will be one of the dimensions => Perimeter = a*4; Dimension = a;

The important part is to test wether Math.sqrt(n) is an integer or not. But you can google a bit for that one, cause it's not that hard.

Now , if Math.sqrt(n) is not an integer then the area is that of a rectangle. You have to find a and b , witch is length and width. Lets say n=12; you could find all its divisors, and see wich of them multiplied equals 12. Like : 3*4, 2*6, 1*12. I don't now if you have to get all the posibilities or only one. The perimeter = a+b.

That's just to get you started , hope u understood... so ... next time come with some code
I sorta get what u mean but how do i test it?
Dark Flare Knight is offline   Reply With Quote
Old May 15th, 2005, 11:28 PM   #15
xavier
Professional Programmer
 
xavier's Avatar
 
Join Date: Oct 2004
Location: .ro
Posts: 381
Rep Power: 4 xavier is on a distinguished road
Send a message via Yahoo to xavier
Wink

Quote:
Originally Posted by JDStud6
rectangle perimeter is actually 2*(a+b)

JD
Yes, sorry :o :o i don't know what i was thinking of :o

@Dark.
The way u should do it (i don't know of an easier way) is something like
public boolean isInteger(String s){
try{
       Integer.parseInt(s);
       return true;
}catch(NumberFormatException nfe){
       return false;
}
}

Now, this should work so try making an effort.
__________________
Don't take life too seriously, it's not permanent !
xavier is offline   Reply With Quote
Old May 16th, 2005, 12:52 PM   #16
Dark Flare Knight
Hobbyist Programmer
 
Join Date: Mar 2005
Location: Canada
Posts: 113
Rep Power: 4 Dark Flare Knight is on a distinguished road
Quote:
Originally Posted by xavier
Yes, sorry :o :o i don't know what i was thinking of :o

@Dark.
The way u should do it (i don't know of an easier way) is something like
public boolean isInteger(String s){
try{
       Integer.parseInt(s);
       return true;
}catch(NumberFormatException nfe){
       return false;
}
}

Now, this should work so try making an effort.
Haven't learned half of this stuff yet. I'm only in grade 9 so i have no idea what u wrote.
Dark Flare Knight is offline   Reply With Quote
Old May 16th, 2005, 2:19 PM   #17
xavier
Professional Programmer
 
xavier's Avatar
 
Join Date: Oct 2004
Location: .ro
Posts: 381
Rep Power: 4 xavier is on a distinguished road
Send a message via Yahoo to xavier
I guess you could make an array of possible a^2 like : array = {4,9,16,25,36,81....... } and if the number given by the user is among these, then you have a square, else a rectangle and you can take it from there.
__________________
Don't take life too seriously, it's not permanent !
xavier is offline   Reply With Quote
Old May 17th, 2005, 10:49 AM   #18
Dark Flare Knight
Hobbyist Programmer
 
Join Date: Mar 2005
Location: Canada
Posts: 113
Rep Power: 4 Dark Flare Knight is on a distinguished road
import java.awt.*;
import hsa.Console;
public class probJ2
{
    static Console c = new Console ();
    public static void main (String[] args)
    {
        int num;
        c.clear ();
        c.print ("Enter number of pictures: ");
        do
        {
            num = c.readInt ();
            if (num == 0)
                c.close ();
            else
                if (num % 2 == 0)
                {
                    c.println ((int) Math.sqrt (num));
                }
                else
                {
                    c.println ();
                }
        }
        while (num < 0 || num > 65000);
    }
}

I'm done this much. Can someone help me from here on?
Dark Flare Knight is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 11:48 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC