quadratic equation code
i wrote a code to solve for roots of a quadratic equation. When i gave it values for this equation -> 6x^2 + 5x + 1, it gives answers as -12 and -18 , whereas when i solved using pen and paper answer should be -0.5 and -0.333 i must be making some silly mistake in the code , please can anybody point it out.. import java.util.Scanner; public class quadratic { public static void main(String[] args) { Scanner sc= new Scanner(System.in); System.out.println("Enter the co-effiecient of X^2"); int a=sc.nextInt(); System.out.println("Enter the co-effiecient of X"); int b = sc.nextInt(); System.out.println("Enter the constant"); int c= sc.nextInt(); double D= (b*b)-(4*a*c); System.out.println(D); double root1= ((-b) + (Math.sqrt(D)))/2*a; double root2= ((-b) - (Math.sqrt(D)))/2*a; System.out.println(root1); System.out.println(root2); } }