Results 1 to 10 of 10
  1. #1
    bbtgirl is offline Member
    Join Date
    Jan 2009
    Posts
    4
    Rep Power
    0

    Default 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!

  2. #2
    CJSLMAN's Avatar
    CJSLMAN is offline Moderator
    Join Date
    Oct 2008
    Location
    Mexico
    Posts
    1,159
    Rep Power
    7

    Default 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
    Chris S.
    Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.

  3. #3
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default

    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

  4. #4
    angryboy's Avatar
    angryboy is offline Senior Member
    Join Date
    Jan 2009
    Posts
    742
    Rep Power
    6

    Default

    it much faster to use int sideA = a*a; then to use the Math class.
    USE CODE TAGS--> [CODE]...[/CODE]
    Get NotePad++ (free)

  5. #5
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default

    Quote Originally Posted by angryboy View Post
    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.

  6. #6
    angryboy's Avatar
    angryboy is offline Senior Member
    Join Date
    Jan 2009
    Posts
    742
    Rep Power
    6

    Default

    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...
    USE CODE TAGS--> [CODE]...[/CODE]
    Get NotePad++ (free)

  7. #7
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default

    Quote Originally Posted by angryboy View Post
    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.

  8. #8
    CJSLMAN's Avatar
    CJSLMAN is offline Moderator
    Join Date
    Oct 2008
    Location
    Mexico
    Posts
    1,159
    Rep Power
    7

    Default 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
    Chris S.
    Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.

  9. #9
    angryboy's Avatar
    angryboy is offline Senior Member
    Join Date
    Jan 2009
    Posts
    742
    Rep Power
    6

    Default

    Quote Originally Posted by CJSLMAN View Post
    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().
    USE CODE TAGS--> [CODE]...[/CODE]
    Get NotePad++ (free)

  10. #10
    CJSLMAN's Avatar
    CJSLMAN is offline Moderator
    Join Date
    Oct 2008
    Location
    Mexico
    Posts
    1,159
    Rep Power
    7

    Default ok...

    Oh... OK... sorry if I misunderstood your post... and I agree with both you and Fubarable .... a*a and Math.sqrt().

    Thanks,
    CJSL
    Chris S.
    Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.

Similar Threads

  1. Quadratic Equation
    By jpnym15 in forum New To Java
    Replies: 4
    Last Post: 11-12-2008, 03:29 AM
  2. Quadratic GUI
    By ryn21 in forum New To Java
    Replies: 1
    Last Post: 10-30-2008, 05:58 AM
  3. Formula on Maximum loan..
    By esh21 in forum NetBeans
    Replies: 4
    Last Post: 08-14-2008, 02:27 PM
  4. Help with quadratic equation in java
    By paul in forum New To Java
    Replies: 1
    Last Post: 07-25-2007, 08:23 PM
  5. What is the formula?
    By yuchuang in forum New To Java
    Replies: 3
    Last Post: 04-30-2007, 10:00 PM

Posting Permissions

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