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

Équation

This Java code prompts a user to enter coefficients a, b, and c for an equation ax^2 + bx + c = 0, calculates the discriminant, and outputs the solutions or states there are no real solutions based on the discriminant.

Uploaded by

Juvenal Rumang
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)
15 views1 page

Équation

This Java code prompts a user to enter coefficients a, b, and c for an equation ax^2 + bx + c = 0, calculates the discriminant, and outputs the solutions or states there are no real solutions based on the discriminant.

Uploaded by

Juvenal Rumang
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

java

import java.util.Scanner;

public class EquationSecondDegre {

public static void main(String[] args) {

Scanner scanner = new Scanner(System.in);

System.out.println("Entrez les coefficients a, b et c de l'équation ax^2 + bx + c = 0 :");

double a = scanner.nextDouble();

double b = scanner.nextDouble();

double c = scanner.nextDouble();

double discriminant = b * b - 4 * a * c;

if (discriminant > 0) {

double x1 = (-b + Math.sqrt(discriminant)) / (2 * a);

double x2 = (-b - Math.sqrt(discriminant)) / (2 * a);

System.out.println("Les solutions de l'équation sont : x1 = " + x1 + ", x2 = " + x2);

} else if (discriminant == 0) {

double x = -b / (2 * a);

System.out.println("L'équation admet une solution double : x = " + x);

} else {

System.out.println("L'équation n'a pas de solution réelle.");

You might also like