• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

N00b Question: Quadratic Equation Code

 
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I've been doing Java for about two weeks. I'm having a lot of trouble understanding the code for the quadratic equation. Can someone walk me through it please?

 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It'd be best if you walk through it line by line, telling us what you think it does, and what about each line you do not understand. I'm willing to bet that this exercise helps in and of itself.
 
Rancher
Posts: 1090
14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In a quadratic equation (Ax^2 + Bx + C = 0), A cannot be 0. If A=0, it is a linear equation.

See if it helps.

Chan.
 
Sam Pauken
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
1. This assign the class for the code.
3. Not sure what all of this specifically means yet. My best guess is that this let me do inputs.
4. This is for "bx" in the equation. I don't know what parseDouble does, but I know args[0] is for my first input.
5. This is for "c" in the equation. args[1] is for my 2nd input.
7. I have no clue. What's with the 4.0? Why 4.0 instead of 4?
8. Math.sqrt take the square root. That's all I got.
10-11 I have no clue. I don't understand why we're doing what we're doing.
13. Writes the value for root1 to the Console.
14. Writes the value for root2 to the Console.

 
Chan Ag
Rancher
Posts: 1090
14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
See if you'd want to go through this ---> http://www.teacherschoice.com.au/maths_library/algebra/alg_6.htm
 
Sam Pauken
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks, I just did some reading into this. I understand the math now. Still not sure on the code though.
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OK, here are some hints to help you along...

Sam Pauken wrote:1. This assign the class for the code.


The correct word is declares. All code must be within a class, so you always need to create at least one. Most large applications can have hundreds if not thousands of classes.

3. Not sure what all of this specifically means yet. My best guess is that this let me do inputs.


Each class can have any number of methods. The main method is the one that the program will start executing (for most program types).

4. This is for "bx" in the equation. I don't know what parseDouble does, but I know args[0] is for my first input.


And your inputs are always strings. You can't do math on strings, so they need to be converted to a numeric type; in this case doubles.

7. I have no clue. What's with the 4.0? Why 4.0 instead of 4?


Most languages have a handful of different numeric types depending upon the nature of the numbers being represented. For the quadratic equation, integers won't do. 4 is an integer literal. 4.0 is a floating point literal.

I'll let you take it from here...
 
Sam Pauken
Ranch Hand
Posts: 84
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Got it! Thanks for your help (and for making me do some of the work on my own).
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Sam Pauken wrote:Got it! Thanks for your help (and for making me do some of the work on my own).


You're welcome! And kudos for appreciating that sometimes all you need is nudge in the right direction to figure things out on your own. Not everybody does.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic