Revising the quadractic equation

trying to submit the block of code holds true for every case i.e real and distinct, real and equal, Imaginary
But upon submission it says fail for testcase2
please help!

Hi Kush,
Share your code.

here is my code that I wrote for the problem

import java.util.*; public class Main { static Scanner scn = new Scanner(System.in); public static void main(String args[]) { int a = scn.nextInt(); int b = scn.nextInt(); int c = scn.nextInt(); double root1,root2; double determinant = b * b - 4 * a * c; // condition for real and different roots if(determinant > 0) { root1 = (-b - Math.sqrt(determinant)) / (2 * a); root2 = (-b + Math.sqrt(determinant)) / (2 * a); int r1 = (int)Math.round(root1); int r2 = (int)Math.round(root2); System.out.format(“Real and Distinct”+ “\n” + r1 + " " + r2); } // Condition for real and equal roots else if(determinant == 0) { root1 = root2 = -b / (2 * a); int r3 = (int)Math.round(root1); System.out.format(“Real and Equal” + “\n” + r3); } // If roots are not real else { System.out.format(“Imaginary”); } } }

Hi @kushaggarwal

Please paste your code in ide.codingblocks.com and save it. Then send the link of the code here. It’ll help us to debug your code better.

sorry wrong one this is the code for quadractic one

Hi @kushaggarwal

I have the required changes to your code. In case of equal roots, you still need to print both of the roots.

The formatted line is

System.out.format(“Real and Equal” + “\n” + r3 + " " + r3);