![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#11 |
|
Professional Programmer
|
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. |
|
|
|
|
|
#12 |
|
Programmer
|
rectangle perimeter is actually 2*(a+b)
JD |
|
|
|
|
|
#13 |
|
Hobbyist Programmer
|
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.
|
|
|
|
|
|
#14 | |
|
Hobbyist Programmer
Join Date: Mar 2005
Location: Canada
Posts: 113
Rep Power: 4
![]() |
Quote:
|
|
|
|
|
|
|
#15 | |
|
Professional Programmer
|
Quote:
@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 ! |
|
|
|
|
|
|
#16 | |
|
Hobbyist Programmer
Join Date: Mar 2005
Location: Canada
Posts: 113
Rep Power: 4
![]() |
Quote:
|
|
|
|
|
|
|
#17 |
|
Professional Programmer
|
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 ! |
|
|
|
|
|
#18 |
|
Hobbyist Programmer
Join Date: Mar 2005
Location: Canada
Posts: 113
Rep Power: 4
![]() |
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? |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|