Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2019
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.28 KB | None | 0 0
  1. import java.util.Scanner;
  2. import java.util.Locale;
  3.  
  4. public class SecondDegreeEquationv2 {
  5.    
  6.     static void sde(int a, int b, int c) {
  7.        
  8.         if (a==0) {
  9.             if (b==0) {
  10.                 if (c==0) {
  11.                     System.out.println("infinite solutions");
  12.                 }
  13.                 else {
  14.                     System.out.println("undetermined");
  15.                 }      
  16.             }
  17.             else {
  18.                 double x = (-c*1.0)/(b);
  19.                
  20.                 System.out.printf("%d %d %d %.4f first degree equation\n", a, b, c, x);
  21.             }
  22.            
  23.         }
  24.         else {
  25.             if (b*b >= 4*a*c) {
  26.                 if (b*b == 4*a*c) {
  27.                     double x = (-b)/(2.0*a);
  28.                    
  29.                     System.out.printf("%.4f double solution\n", x);
  30.                 }
  31.                 else {
  32.                     double x1 = (-b+Math.sqrt(b*b-4.0*a*c))/(2.0*a);
  33.                     double x2 = (-b-Math.sqrt(b*b-4.0*a*c))/(2.0*a);
  34.                    
  35.                     System.out.printf("%.4f and %.4f\n", x1, x2);
  36.                 }
  37.             }
  38.             else {
  39.                 double real = (-b)/(2.0*a);
  40.                 double im = Math.abs(Math.sqrt(4.0*a*c-b*b)/(2.0*a));
  41.                
  42.                 System.out.printf("%.4f + %.4fi and %.4f - %.4fi\n", real, im, real, im);
  43.             }
  44.            
  45.            
  46.         }
  47.        
  48.        
  49.     }
  50.    
  51.     public static void main(String[] args) {
  52.        
  53.         Scanner kbd = new Scanner( System.in ).useLocale( Locale.US );
  54.        
  55.         while (kbd.hasNext()) {
  56.            
  57.             int a = kbd.nextInt();
  58.             int b = kbd.nextInt();
  59.             int c = kbd.nextInt();
  60.            
  61.             sde(a, b, c);
  62.            
  63.         }
  64.        
  65.     }
  66.  
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement