Java examples for Language Basics:Operator
Quadratic equation solver with user input
import java.util.Scanner; public class Main { public static void main(String[] arg) { Scanner keyboard = new Scanner(System.in); System.out.print("Enter a,b,c of equation ax^2+bx+c=0:"); double a = keyboard.nextDouble(); double b = keyboard.nextDouble(); double c = keyboard.nextDouble(); double delta = b * b - 4.0 * a * c; double root1, root2; if (delta >= 0) { root1 = (-b - Math.sqrt(delta)) / (2.0 * a); root2 = (-b + Math.sqrt(delta)) / (2.0 * a); System.out.println("Two real roots:" + root1 + " " + root2); } else {//from w ww . j av a 2 s .co m System.out.println("No real roots"); } } }