My code will not run properly. I need help fixing the errors in my code import java.util.Scanner; public class Quad
Posted: Mon May 09, 2022 6:58 am
My code will not run properly. I need help fixing the errors in
my code
import java.util.Scanner;
public class Quad
{
private int a;
private int b;
private int c;
public Quad()
{
a = 1;
b = 1;
c = 1;
public Quad (int a, int b, int c)
{
this.a = a;
this.b = b;
this.c = c;
public double root1()
{
double top = -b +
Math.pow(b,2) - 4 * a * c);
double bot =
2 * a
return top / bot;
}
public double root2()
{
double top = -b -
Math.pow(b,2) - 4 * a * c);
double bot =
2 * a
return top / bot;
@Override
public String toString()
{
return a + "x^2 + " + b +
"x + " + c;
}
}
class Main
{
public static void main(String[]
args)
{
Scanner in = new
Scanner(System.in);
System.out.print("Enter
the value of a: ");
int a =
in.nextInt();
System.out.print("Enter
the value of b: ");
int b =
in.nextInt();
System.out.print("Enter
the value of c: ");
int c =
in.nextInt();
Quadratic n1 = new
Quadratic(a,b,c);
System.out.println("n1 = "
+ n1.toString());
System.out.println("root1
= " + n1.root1());
System.out.println("root2
= " + n1.root2());
System.out.println("disc =
" + n1.discriminant());
}
}
my code
import java.util.Scanner;
public class Quad
{
private int a;
private int b;
private int c;
public Quad()
{
a = 1;
b = 1;
c = 1;
public Quad (int a, int b, int c)
{
this.a = a;
this.b = b;
this.c = c;
public double root1()
{
double top = -b +
Math.pow(b,2) - 4 * a * c);
double bot =
2 * a
return top / bot;
}
public double root2()
{
double top = -b -
Math.pow(b,2) - 4 * a * c);
double bot =
2 * a
return top / bot;
@Override
public String toString()
{
return a + "x^2 + " + b +
"x + " + c;
}
}
class Main
{
public static void main(String[]
args)
{
Scanner in = new
Scanner(System.in);
System.out.print("Enter
the value of a: ");
int a =
in.nextInt();
System.out.print("Enter
the value of b: ");
int b =
in.nextInt();
System.out.print("Enter
the value of c: ");
int c =
in.nextInt();
Quadratic n1 = new
Quadratic(a,b,c);
System.out.println("n1 = "
+ n1.toString());
System.out.println("root1
= " + n1.root1());
System.out.println("root2
= " + n1.root2());
System.out.println("disc =
" + n1.discriminant());
}
}