Whats wrong in my code . how can i improve it

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

	}



}

}

@Harsh_Sonwani Bro code logic is fully correct just some typos were left like:-

  • The roots should be in a same line and be space separated.
  • No need to print roots for imaginary case
  • Or real and equal ke liye imaginary part nahin print krna same root do baar print krna hai.

Take care of output format or you will stuck forever :joy:.
If your query is resolved then mark it resolved , pfa code with corrections below:-
Corrections

import java.util.Scanner;

public class Main {

public static void main(String args[]) {

Scanner scn = new Scanner(System.in);

int a = scn.nextInt();

int b = scn.nextInt();

int c = scn.nextInt();

double s = b * b - (4 * a * c);

if (s > 0) {

System.out.println(“Real and Distinct”);

int r1 = (int) -(b + Math.sqrt(s)) / (2 * a);

int r2 = (int) (-b + Math.sqrt(s)) / (2 * a);

System.out.print(r1 + " " + r2);

} else if (s < 0) {

System.out.println(“Imaginary”);

} else {

System.out.println(“Real and Equal”);

int r1 = (int) (-b / (2 * a));

System.out.print(r1 + " " + r1);

}

}

}