Advertisement
Guest User

Untitled

a guest
Jun 27th, 2017
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  1. import static java.lang.Math.*;
  2.  
  3. // one class needs to have a main() method
  4. public class HelloWorld
  5. {
  6. // arguments are passed using the text field below this editor
  7. public static void main(String[] args) {
  8. int a = 1;
  9. int b = 3;
  10. int c = -4;
  11. int delta = b*b-4*a*c;
  12. System.out.println(sqrt(delta));
  13. double pierwiastek_1 = (-b+(sqrt(delta)))/2*a;
  14. double pierwiastek_2 = (-b-(sqrt(delta)))/2*a;
  15. double pierwiastek_sam = -b/2*a;
  16. if (delta<0)
  17. System.err.println("Równanie kwadratowe nie ma pierwiastków");
  18. else if (delta==0)
  19. System.out.println("Równanie ma tylko jeden pierwiastek: " + pierwiastek_sam);
  20. else
  21. System.out.println("Pierwiastkami tego równania kwadratowego są: " + pierwiastek_1 + " oraz " + pierwiastek_2);
  22.  
  23.  
  24.  
  25.  
  26. // TODO code application logic here
  27. }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement