Computer Applications

The standard form of quadratic equation is represented as:
ax2 + bx + c = 0

where d= b2 - 4ac, known as 'Discriminant' of the equation.

Write a program to input the values of a, b and c. Calculate the value of discriminant and display the output to the nearest whole number.

Java

Java Math Lib Methods

45 Likes

Answer

import java.util.Scanner;

public class KboatQuadEq
{
    public static void main(String args[]) {
        
        Scanner in = new Scanner(System.in);
        
        System.out.print("Enter a: ");
        int a = in.nextInt();
        
        System.out.print("Enter b: ");
        int b = in.nextInt();
        
        System.out.print("Enter c: ");
        int c = in.nextInt();
        
        double d = Math.pow(b, 2) - (4 * a * c);
        long roundedD = Math.round(d);
        
        System.out.println("Discriminant to the nearest whole number = " + roundedD);
    }
    
}

Variable Description Table

Program Explanation

Output

Answered By

16 Likes


Related Questions