#9965: 求解為什麼測資都對還NA60%...........


q0978298512 (超人)

學校 : 國立屏東大學
編號 : 50344
來源 : [218.164.50.183]
最後登入時間 :
2015-09-23 23:40:07
a006. 一元二次方程式 | From: [118.171.192.42] | 發表日期 : 2015-06-30 20:59

import java.util.Scanner; 
public class text3 {
    
    public static void main(String[] args) {
    Scanner sever = new Scanner(System.in);
    while (sever.hasNext())
    {
         int a = sever.nextInt();
      int b = sever.nextInt();
      int c = sever.nextInt();
      if (a>0 && (b^2-4*a*c) >=0)
      {
      Double x = (-b+Math.sqrt(b*b-4*a*c))/(2*a);
      Double y = (-b-Math.sqrt(b*b-4*a*c))/(2*a);
     
      String sx = Double.toString(x);
      String sy = Double.toString(y);
      //System.out.println(sx);
      //System.out.println(sx.subSequence(1, 3));
      //System.out.println(sx.subSequence(0, sx.length()-2));
      //System.out.println(sx.length());
      if (x == 0)
      {
      System.out.println("Two same roots x=" + sx.subSequence(0, sx.length()-2));
      }
      else
      {
      if(x>y)
      {
      System.out.println("Two different roots x1=" + sx.subSequence(0, sx.length()-2) + " , x2=" + sy.subSequence(0, sy.length()-2));
      }
      else
      {
      System.out.println("Two different roots x1=" + sy.subSequence(0, sy.length()-2) + " , x2=" + sx.subSequence(0, sx.length()-2));
      }
      }
      }
      else
      {
      System.out.println("No real root");      
      }
    }
    }
}

 
ZeroJudge Forum