#18222: 看起來沒甚麼問題 Bt 最後測出來 WA (line:2) 您共輸出 1 行。


z85385637 (M-Kai)


import java.util.Scanner;

public class a006 {

public static void main(String[] args) {
Scanner sc= new Scanner(System.in);

int a = sc.nextInt();
int b = sc.nextInt();
int c = sc.nextInt();
int h = (b*b)-(4*a*c);
double d = Math.sqrt(h);
int x1 = (int)(-b + d)/(2*a);
int x2 = (int)(-b - d)/(2*a);
if(h>0) {
System.out.printf("Two different roots x1="+x1+" , x2="+x2);
}else if(h==0) {

System.out.printf("Two same roots x="+x1);
}else {
System.out.printf("No real root");
}

}

}

#18223: Re:看起來沒甚麼問題 Bt 最後測出來 WA (line:2) 您共輸出 1 行。


z85385637 (M-Kai)


import java.util.Scanner;

public class a006 {

public static void main(String[] args) {
Scanner sc= new Scanner(System.in);

int a = sc.nextInt();
int b = sc.nextInt();
int c = sc.nextInt();
int h = (b*b)-(4*a*c);
double d = Math.sqrt(h);
int x1 = (int)(-b + d)/(2*a);
int x2 = (int)(-b - d)/(2*a);
if(h>0) {
System.out.printf("Two different roots x1="+x1+" , x2="+x2);
}else if(h==0) {

System.out.printf("Two same roots x="+x1);
}else {
System.out.printf("No real root");
}

}

}


求解