00:01
In this video, we will create a program that solves the quadratic equation by prompting the user to enter values for a, b, and c, displaying the result based on the discriminant.
00:08
If the discriminant is positive, the quadratic equation will be solved and the two roots will be displayed.
00:13
If it is zero, the singular root will be calculated and displayed.
00:17
Otherwise, the discriminant is negative, and we will display a message to the user that there are no real roots.
00:23
I've already defined our class as well as the main method with any it.
00:26
I've also imported java .util .scanner, since we know we'll be taking use.
00:30
Or input.
00:31
So the first thing we can do is go into our main method and create a new scanner object by calling scanner with the argument system .in, which allows keyboard input to be read from inside our java application.
00:55
After this, we'll want to prompt the user to enter values a, b, and c, and save h using the method next double of java .utal .scanner class, which scans the next token of the next token of the input as a double so we can use system .out .println to tell the user to enter a value for a.
01:25
After this we're going to want to declare double a equals input.
01:31
Next double.
01:37
So we can go ahead and copy these two lines since we'll be doing the same thing for b and c.
01:52
So we'll be doing the same thing for b and c.
01:57
We can just switch our a's with b's and c's accordingly.
02:08
And at this point, we'll want to declare variable d and calculate our discriminant, since now we have doubles for a, b, and c from our user.
02:18
We can declare double d equals b times b.
02:26
Right now we're looking at our discriminant equation at the right -hand side of the screen.
02:34
B times b squared minus 4 times a times c.
02:42
So now we have our discriminant.
02:45
At this point, we'll want to check whether it is positive 0 or negative.
02:49
So we're going to use an if statement for this...