Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Shavit Borisov
- // CW
- import java.util.Scanner;
- public class QuadraticEquationV2 {
- public static void main(String[] args)
- {
- Scanner in = new Scanner (System.in);
- int a, b, c;
- System.out.println("Enter the values of a, b and c for the quadratic equation:");
- a = in.nextInt();
- b = in.nextInt();
- c = in.nextInt();
- double delta = Math.pow((double)b, 2) - 4 * a * c;
- double x1 = (-b + Math.sqrt(delta)) / (2 * a);
- double x2 = (-b - Math.sqrt(delta)) / (2 * a);
- if (delta < 0)
- {
- System.out.println("There are no roots for your equation!");
- }
- else if (delta == 0)
- {
- System.out.printf("There is one root for your equation, it is %.2f", x1);
- }
- else if (delta > 0)
- {
- System.out.printf("There are two roots for your equation, they are %.2f and %.2f", x1, x2);
- }
- in.close();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment