Advertisement
Paarzivall

Untitled

Mar 6th, 2019
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.91 KB | None | 0 0
  1. package projekt1;
  2.  
  3. /*
  4. final - stała (w zmiennej)
  5. final w klasie (nie można z tej klasy dziedziczyć)
  6. */
  7.  
  8. public class klasa1 {
  9.  
  10.     public static void main(String[] args) {
  11.         double a = 0, b = 0, c = 0;
  12.        
  13.         //ciągnięcie z linii komend
  14.         a = Double.parseDouble(args[0]);
  15.         b = Double.parseDouble(args[1]);
  16.         c = Double.parseDouble(args[2]);
  17.        
  18.         //final double a = 10;
  19.         //final double b = 4;
  20.         //final double c = 2;
  21.        
  22.         double delta = Math.pow(b, 2) - 4 * a * c;
  23.        
  24.         if(delta < 0) {
  25.             System.out.println("Brak pierwiastków");
  26.         }
  27.         else {
  28.             double sqrtDelta = Math.sqrt(delta);
  29.            
  30.             if(delta > 0) {
  31.                 System.out.println("x1 = "+Double.toString((-b - sqrtDelta)/(2*a)));
  32.                 //Double.toString <- nie jest wymagane jest wykonywane niejawnie przez kompilator
  33.                 System.out.println("x2 = "+(-b + sqrtDelta)/(2*a));
  34.             }else {
  35.                 System.out.println("x1 = "+(-b)/(2*a));
  36.             }
  37.         }
  38.     }
  39.  
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement