The problem is " Conversion = '-'". The source code is listed below. This is a program used to caculating the value of Coefficent A, B, and C based on the quadratic function.
import java.util.Scanner;
public class RootsTestHamer {
public static void main(String[] args) {
//declare variables
double a, b, c;
double r1, r2;
Scanner input = new Scanner(System.in); // Create a Scanner
// prompts user to enter values for coefficents A, B, and C
System.out.print("Enter the A coefficent:");
a = input.nextDouble();
System.out.print("Enter the B coefficent:");
b = input.nextDouble();
System.out.print("Enter the C coefficent:");
c = input.nextDouble();
// calucating roots
r1 = ( Math.pow(b,2) - (4 * a * c));
r1 = (-b + (Math.sqrt(r1))) / (2 * a);
r2 = ( Math.pow(b,2) - (4 * a * c));
r2 = (-b - (Math.sqrt(r2))) / (2 * a);
// calls the method and determines # of roots
double r = roots (a, b, c);
// if statements and display
if (r > 1) {
System.out.printf("%.0f, %.of, and %.0f coefficients have %.0f real roots:",a, b, c, r);
System.out.printf("\n\tR1 = %.2f",r1);
System.out.printf("\n\tR1 = %.2f",r2);
}
else if (r == 1)
{
System.out.printf("%.0f, %.of, and %.0f coefficients have %.0f real roots:",a, b, c, r);
System.out.printf("\n\tR1 = %.2f",r1);
}
else if (r == 0) {
System.out.printf("%.0f, %.of, and %.0f coefficients have %.0f real roots:",a, b, c);
}
}
//user - defined root method
public static double roots(double a, double b, double c) {
double roots = 0;
//number of roots
if (Math.pow(b,2) - (4 * a * c) > 0) {
roots = 2;
}
else if (Math.pow(b,2) - (4 * a * c) == 0) {
roots = 1;
}
else if (Math.pow(b,2) - (4 * a * c) < 0) {
roots = 0;
}
return roots;
}
}
I attempted to run the code. After entering the value 1, 2,3 for coefficents A, B,and C, the code returned Exception in thread "main" java.util.UnknownFormatConversionException: Conversion = '-'