Advertisement
Guest User

abc

a guest
Nov 30th, 2015
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.99 KB | None | 0 0
  1. import java.util.*;
  2. import java.lang.Math.*;
  3.  
  4.  
  5. public class First {
  6.  
  7. public static void main(String[] args){
  8.  
  9.     Scanner sc = new Scanner(System.in);
  10.     System.out.println("podaj a");
  11.     double a=sc.nextDouble();
  12.     System.out.println("podaj b");
  13.     double b=sc.nextDouble();
  14.     System.out.println("podaj c");
  15.     double c=sc.nextDouble();
  16.     double delta = (b*b)-(4*a*c);
  17.     if(delta == 0){
  18.         double x1 = (-b)/(2* a);
  19.         System.out.println("jeden pierwiastek: " + x1);
  20.         }
  21.  
  22.     else if (delta > 0)
  23.         {
  24.         double x1 = (-b+Math.sqrt(delta)) / (2 * a);
  25.         double x2 = (-b-Math.sqrt(delta)) / (2 * a);
  26.         System.out.println("Dwa pierwiastki:"  +x1 + "i "  +x2);
  27.         }
  28.  
  29.     else
  30.     {
  31.  
  32.         double urojona=((Math.sqrt(Math.abs(delta)))/(2*a));
  33.         double rzeczywista=(-b/(2*a));
  34.         System.out.println(rzeczywista+" + "+urojona+"i");
  35.         System.out.println(rzeczywista+" - "+urojona+"i");
  36.         }
  37.     }
  38.  
  39.  
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement