• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Devaka Cooray
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Junilu Lacar
  • Paul Clapham
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • salvin francis
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

Quadratic Equation  RSS feed

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi! I am really new to JAVA and am trying to figure out how to make it work.
I am trying to write a basic java program for a quadratic equation where b2 – 4ac is the discriminant being tested for.  
I would like the program to prompt the user to enter values for a, b, and c and displays the result based on the discriminant.  I’m trying to make it so that if the discriminant is positive, two roots will be displayed, and if the discriminant is 0, one root is displayed.  Otherwise, I want it to display “The equation has no real roots”.
I heard that using Math.pow(x, 0.5) to compute the square root of x would work the best.
Would very much appreciate some examples or help!

Thank you!
 
Saloon Keeper
Posts: 2134
80
Eclipse IDE Google Web Toolkit Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Let me understand correctly, if user enters : a=2, b=3, c=4, your program would do

(3 * 3)– (4 *2 *4 ) = -23

And your output will be "The equation has no real roots" since its negative 23.

I would break your code into 3 parts:
1. Taking entry from user for a,b,c
2. Calculating equation result.
3. Giving an output based on the result

Which part are you stuck at ?
What have you done so far ?

Hint, You can use Math.sqrt() for the square root.
 
Zachary Kang
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have not done any of it yet, for I am trying to understand how I would go about starting this.  What is the notation?  How would I write something like this?
 
Rancher
Posts: 3353
33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Start by looking at the methods in the Math class to see what is available.
 
salvin francis
Saloon Keeper
Posts: 2134
80
Eclipse IDE Google Web Toolkit Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Zachary Kang wrote:I have not done any of it yet, for I am trying to understand how I would go about starting this.  What is the notation?  How would I write something like this?


Hi Zachary Kang,
Are you aware of the following ?
  • Writing a program that simply prints "Hello world"
  • Using variables in your code
  • Doing calculations on one variable and assigning the result to another
  • Using classes
  • Using methods


  • You may have to look at the java tutorials here: https://docs.oracle.com/javase/tutorial/ to learn the basics of Java.
    Keep us updated on your progress and we can help you out if you are stuck.
     
    All of the world's problems can be solved in a garden - Geoff Lawton. Tiny ad:
    RavenDB is an Open Source NoSQL Database that’s fully transactional (ACID) across your database
    https://coderanch.com/t/704633/RavenDB-Open-Source-NoSQL-Database
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!