phannguyenhongthuong@gmail.com

 avatar
pigeljbio
plain_text
4 years ago
1.6 kB
7
Indexable
import java.util.Scanner;

public class Main{

     public static void main(String []args){
        Scanner sc = new Scanner(System.in);
        short a = sc.nextShort();
        short b = sc.nextShort();
        short c = sc.nextShort();
        float x1 = (float)Math.sqrt(-c/b);
        double x2 = (float) - x1;
        short delta = b*b - 4*a*c; 
        float x3 = (float) (-b + Math.sqrt(delta))/(2*a);
        float x4 = (float) - x3;
       // if ()
            if (a == 0){
                if (b == 0 && c == 0){
                    System.out.print("INF");
                }else if (b == 0 && c != 0){
                    System.out.print("NO");
                }else{
                    System.out.printf("%2f", (float)-c/b);
                }
            if (a != 0){
                if (b == 0 && c == 0){
                    System.out.print(0);
                }else if (b == 0 && c < 0){
                    System.out.print("NO");
                }else if(b == 0 && c > 0){
                    if(x1 > x2){
                        float doi = x1;
                        x1 = x2;
                        x2 = doi;
                    }
                    System.out.printf("%2f %2f",x1,x2 );
                }else{
                    if(delta > 0){
                        System.out.printf("%2f %2f",x3,x4 );
                    }else if (delta == 0){
                        System.out.printf("%2f", x3);
                    }else{
                    System.out.print("NO");  
                    }
            
                }
            }    
           }
     }
}
Editor is loading...