# program for a quadratic formula

• 01-30-2009, 02:55 AM
bbtgirl
program for a quadratic formula
im suppose to write a program to compute the solutions for a quadratic formula, where a=4, b=30, and c=10. the perameters must be declared as ints
how do i do that? there's a specific code for if i want to square something, i think its Math....something something... but i dont remember. plz help!
• 01-30-2009, 03:13 AM
CJSLMAN
Math ...
Here's the link to the Math class and it's methods:
Math (Java Platform SE 6)

Luck,
CJSL

PS: I think you're looking for the sqrt() method
• 01-30-2009, 03:15 AM
Fubarable
What you need is the Java API. It will have all the info you need. Here's the API for the Math class:
Math (Java Platform SE 6)
And the "Master" API:
Overview (Java Platform SE 6)

Luck
• 01-30-2009, 05:28 AM
angryboy
it much faster to use int sideA = a*a; then to use the Math class.
• 01-30-2009, 05:37 AM
Fubarable
Quote:

Originally Posted by angryboy
it much faster to use int sideA = a*a; then to use the Math class.

I'm a bit confused how you would avoid using the Math class for a general solution to the quadratic equation? I suppose you could use Newton's approximation of square roots, but that seems a bit overkill.
• 01-30-2009, 06:12 AM
angryboy
Quote:

there's a specific code for if i want to square something, i think its Math....something something...
i didn't mean to avoid the Math class all together. I was just suggesting that its faster to square the numbers using a*a. rather than using Math.pow().

you could actually cal for sqrt, but its a crazy math formular. better to use Math.sqrt() for that part...
• 01-30-2009, 06:21 AM
Fubarable
Quote:

Originally Posted by angryboy
i didn't mean to avoid the Math class all together. I was just suggesting that its faster to square the numbers using a*a. rather than using Math.pow().

I agree 100%. I didn't see where someone had suggested using Math.pow(), just sqrt, and probably that confused me.
• 01-30-2009, 01:43 PM
CJSLMAN
huh?
Angryboy... you on something? Let's see... I give a link to the Math class and tell the OP that the sqrt() is probably what is needed. How did you come to the conclusion that I was suggessting that the OP develop the sqrt() method? I think it would be obvious that I'm refering to the sqrt() method in the link to the Math class.
As for the a*a vs Math.pow(), yeah... that's sounds pretty logical...

CJSL
• 01-30-2009, 06:50 PM
angryboy
Quote:

Originally Posted by CJSLMAN
Angryboy... you on something?

lol nah, you misunderstood what i wrote. maybe you on something...
like i said to fubarable, use a*a and Math.sqrt().
• 01-30-2009, 07:06 PM
CJSLMAN
ok...
Oh... OK... sorry if I misunderstood your post... and I agree with both you and Fubarable .... a*a and Math.sqrt().

Thanks,
CJSL