NA錯誤:
您的答案為: Two same roots x=-4 正確答案為: Two same roots x=-1
package test;
import java.util.Scanner;
public class test {
public static void main(String[]args){
Scanner sc=new Scanner(System.in);
while(sc.hasNext()){
double a=sc.nextDouble();
double b=sc.nextDouble();
double c=sc.nextDouble();
double num1=(-b)/2*a;
double num2=Math.sqrt(b*b-4*a*c)/2*a;
double total=b*b-4*a*c;
int x1=(int)(num1+num2);
int x2=(int)(num1-num2);
if(total>0){
System.out.println("Two different roots x1="+x1+" , x2="+x2);}
else if(total==0){
System.out.println("Two same roots x="+x1);}
else {System.out.println("No real root");}
}}}
但我自己跑都沒錯,也沒出現NA的錯誤,有人可以幫我解一下嗎