//QuadraticFormula.java import java.awt.*; import javax.swing.*; public class QuadraticFormula extends JApplet { public void init() { double a, b, c, x1, x2; String input; input = JOptionPane.showInputDialog("Enter a"); a = Double.parseDouble(input); input = JOptionPane.showInputDialog("Enter b"); b = Double.parseDouble(input); input = JOptionPane.showInputDialog("Enter c"); c = Double.parseDouble(input); x1 = (-b + Math.sqrt(b*b - 4*a*c)) / (2 * a); x2 = (-b - Math.sqrt(b*b - 4*a*c)) / (2 * a); JOptionPane.showMessageDialog(null, "x1="+x1+" x2="+x2); } } //we'll learn how to deal with a==0 and discriminant<0 later