Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
6 views1 page

Quad

The document presents a Java program that calculates and displays the roots of a quadratic equation of the form ax² + bx = 0, with hardcoded coefficients. It computes the discriminant and determines the nature of the roots based on its value. An example output is provided for coefficients a = 2 and b = 4, showing the results of the calculations.

Uploaded by

naryugam
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views1 page

Quad

The document presents a Java program that calculates and displays the roots of a quadratic equation of the form ax² + bx = 0, with hardcoded coefficients. It computes the discriminant and determines the nature of the roots based on its value. An example output is provided for coefficients a = 2 and b = 4, showing the results of the calculations.

Uploaded by

naryugam
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

Here’s a Java program that displays the roots of a quadratic equation of the form ax² + bx = 0

(note: no constant term c, so it's a special case). It calculates the discriminant D and describes
the nature of the roots without using Scanner (i.e., input values are hardcoded):

✅ Java Code:
java
CopyEdit
public class QuadraticRoots {
public static void main(String[] args) {
// Coefficients of the quadratic equation: ax² + bx = 0
double a = 2; // Change as needed
double b = 4; // Change as needed

System.out.println("Given equation: " + a + "x² + " + b + "x = 0");

// Discriminant formula: D = b² - 4ac, but c = 0 here


double D = b * b;

System.out.println("Discriminant (D) = " + D);

// Roots using: x(ax + b) = 0 → x = 0 or ax + b = 0


double root1 = 0;
double root2 = -b / a;

System.out.println("Roots are: x = " + root1 + " and x = " +


root2);

// Nature of roots
if (D > 0) {
System.out.println("Nature of Roots: Real and Unequal");
} else if (D == 0) {
System.out.println("Nature of Roots: Real and Equal");
} else {
System.out.println("Nature of Roots: Complex (Imaginary)");
}
}
}

📌 Sample Output (for a = 2, b = 4):

mathematica
CopyEdit
Given equation: 2.0x² + 4.0x = 0
Discriminant (D) = 16.0
Roots are: x = 0.0 and x = -2.0
Nature of Roots: Real and Unequal

You might also like