#2366: 為什麼有兩根時 另一根都沒出現


KITTEN101 (Cloud Cat)


import java.util.Scanner;

class cato4{//輸入x,y來算加減乘除
 public static void main(String[] args){
  Scanner input= new Scanner(System.in);
  while(input.hasNext()){
   int a= input.nextInt();  //get an int from keyboard
   int b= input.nextInt();  //get an int from keyboard
   int c= input.nextInt();  //get an int from keyboard
   int d= (b*b-(4*a*c));
   if(d==0){
   int f=(-b/2*a);
   System.out.print("Two same roots x="+f);
   }
   if(d<0){
   System.out.println("No real root");
   }
   if(d>0){
   double e=Math.sqrt(b*b-(4*a*c));
   System.out.print("Two different roots x1="+((-b+e)/(2*a))+",x2="+((b-e)/(2*a)));
   }
  }
 }
}