F
F
Fedor unknown2020-08-22 12:04:29
Java
Fedor unknown, 2020-08-22 12:04:29

Did you solve the problem correctly?

Given:
Write a program to solve a quadratic equation. A quadratic equation is an equation of the form ax2 + bx + c = 0; Please note that the input and result can be with a decimal part.

my decision:

package java2;
import java.util.Scanner;
import java.math.*;

public class SecondHomeWork {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        System.out.println("Введите значение a: ");
        double valueA = scan.nextDouble();
        System.out.println("Введите значение b: ");
        double valueB = scan.nextDouble();
        System.out.println("Введите значение c: ");
        double valueC = scan.nextDouble();
        double result = (valueB * valueB) - (4 * valueA * valueC);
        System.out.println(result);


    }
}

Answer the question

In order to leave comments, you need to log in

3 answer(s)
G
GavriKos, 2020-08-22
@GavriKos

Not right. Even mathematically wrong.
b^2-4ac is the discriminant formula. Not roots.

J
Jacen11, 2020-08-22
@Jacen11

Double can count incorrectly, don't use it in calculations
After all, what's stopping you from checking the program's performance. Calculate on a piece of paper and compare with what you counted

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question