Calculate Quadratic Equation - Java Algorithm

Java examples for Algorithm:Number

Description

Calculate Quadratic Equation

Demo Code

import java.util.Scanner;

public class QuadraticEquation {

  public static void main(String args[]) {
    double a;/*from   w ww .j a v a2  s . c  o m*/
    double b;
    double c;

    Scanner keyboard = new Scanner(System.in);
    System.out.println("Value of a:");
    a = keyboard.nextDouble();

    System.out.println("Value of b:");
    b = keyboard.nextDouble();

    System.out.println("Value of c:");
    c = keyboard.nextDouble();
    keyboard.close();

    System.out.println("x= " + ((-b - Math.sqrt(b * b - 4 * a * c)) / (2 * a)));
    System.out.println("x= " + ((-b + Math.sqrt(b * b - 4 * a * c)) / (2 * a)));
  }
}

Related Tutorials