import java.util.Scanner; public class Andregradsformel { public static void main(String[] args) { Scanner in = new Scanner(System.in); Double a; Double b; Double c; System.out.println("This program solves quadratic equations."); System.out.println("Use integers."); System.out.println("Enter a: "); a = in.nextDouble(); System.out.println("Enter b: "); b = in.nextDouble(); System.out.println("Enter c: "); c = in.nextDouble(); System.out.println("First solution:"); System.out.println((-b+Math.sqrt(b*b-4*a*c))/2*a); System.out.println("Second solution:"); System.out.println((-b-Math.sqrt(b*b-4*a*c))/2*a); } }
While it works, I have two issues with it:
I have come to understand that one can use decimal numbers while working with doubles. How come my program does not accept that as the user input?
Furthermore, once the program is finished, I want the program to run again. I have looked up some tutorials on loops, but I do not understand how I would go about implementing it. Thanks.
EDIT: Tried changing from Double to Float. Still works with integers, but decimalnumbers are still defect.
EDIT2: For some reason, user-input has to entered as "3,4", not "3.4". Solved.