QUADRATIC EQUATIONS - Java

Code-
import java.util.;
public class Main
{
public static void main(String[] args)
{
int a, b, c, root1, root2;
double d;
Scanner s = new Scanner(System.in);
a = s.nextInt();
b = s.nextInt();
c = s.nextInt();
d = b * b - 4 * a * c;
if(d > 0)
{
System.out.println(“Real and Distinct”);
root1 = (int)(( - b + Math.sqrt(d))/(2
a));
root2 = (int)((-b - Math.sqrt(d))/(2a));
System.out.print(root1+" ");
System.out.print(root2);
}
else if(d == 0)
{
System.out.println(“Real and Equal”);
root1 = (int)((-b+Math.sqrt(d))/(2
a));
System.out.println(root1);
}
else
{
System.out.println(“Imaginary”);
}
}
}

Error-
Exception in thread “main” java.util.InputMismatchException
at java.base/java.util.Scanner.throwFor(Scanner.java:939)
at java.base/java.util.Scanner.next(Scanner.java:1594)
at java.base/java.util.Scanner.nextInt(Scanner.java:2258)
at java.base/java.util.Scanner.nextInt(Scanner.java:2212)
at Main.main(Main.java:9)

Exception in thread “main” java.util.InputMismatchException

This error arises when the compiler does not get the type of input that its expecting

I think you might have run your code on hackerblocks without providing custom input.
This type of error is generated in such case.
On hackerblocks, if you wish to run your code, you have to click on provide custom input, then give the required input, and then click on run

@guptaparidhi
Your code is also not right.
it does not handle all the cases.
Try to attempt the question again.

Great answer I agree with you.