I tried multiple methods and I still can't figure out how to make it so that my code asks the user if they want to run it again in java. This is for my college project due in two days.
I've tried a couple of do-while statements but it still doesn't work.
public class Project_2_1
{
public static void main(String args[])
{
System.out.println("My project");
System.out.println("Project_2 Problem_1\n");
System.out.println("This program computes both roots of a quadratic equation,\n");
System.out.println("Given the coefficients A,B, and C.\n");
double secondRoot = 0, firstRoot = 0;
Scanner sc = new Scanner(System.in);
System.out.println("Enter the value of a ::");
double a = sc.nextDouble();
System.out.println("Enter the value of b ::");
double b = sc.nextDouble();
System.out.println("Enter the value of c ::");
double c = sc.nextDouble();
double determinant = (b*b)-(4*a*c);
double sqrt = Math.sqrt(determinant);
if(determinant>0)
{
firstRoot = (-b + sqrt)/(2*a);
secondRoot = (-b - sqrt)/(2*a);
System.out.println("Roots are :: "+ firstRoot +" and "+secondRoot);
}else if(determinant == 0){
System.out.println("Root is :: "+(-b + sqrt)/(2*a));
}
}
}