Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Lab03 {
- public static void main(String[] args) {
- Scanner in = new Scanner(System.in);
- double a, b, c, discriminant;
- System.out.print("Please enter the value of a,b,c: ");
- a = in.nextDouble();
- b = in.nextDouble();
- c = in.nextDouble();
- discriminant = b * b - 4.0 * a * c;
- if (discriminant < 0) {
- System.out.println("The equation has no real roots.");
- } else if (discriminant == 0.0) {
- System.out.println("The root is " + (-b / (2.0 * a)));
- } else {
- System.out.print("The roots are ");
- System.out.print((-b + Math.pow(discriminant, 0.5)) / (2.0 * a));
- System.out.print(" and ");
- System.out.println((-b - Math.pow(discriminant, 0.5)) / (2.0 * a));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement