Advertisement
polpoteu

JAVA Trójmian Kwadratowy

Oct 18th, 2018
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1. package dzielenie.bezpieczne;
  2.  
  3. import static java.lang.Math.sqrt;
  4. import java.util.Scanner;
  5.  
  6. public class DzielenieBezpieczne {
  7.  
  8.  
  9. public static void main(String[] args) {
  10.  
  11. double a, b, c, delta, x1, x2, x0;
  12. Scanner sc = new Scanner(System.in);
  13. System.out.println("Funkcja kwadratowa ");
  14. System.out.println("Ax^2 + Bx + C");
  15. System.out.println("Wprowadź A");
  16.  
  17. a = sc.nextDouble();
  18.  
  19. if (a==0)
  20. System.out.println("To funkcja liniowa...");
  21. else {
  22. System.out.println("Wprowadź B ");
  23. b = sc.nextDouble();
  24. System.out.println("Wprowadź C");
  25. c = sc.nextDouble();
  26.  
  27. delta = (b*b)-(4*(a*c));
  28.  
  29. if (delta < 0) {
  30. System.out.println("Równanie nie ma rozwiązań...");
  31. System.out.println("Delta = " +delta);}
  32. else {
  33. if (delta ==0){
  34. x0 = (-(b))/( 2 * a );
  35. System.out.println("Delta = " +delta);
  36. System.out.println("X0 = " +x0);
  37. }
  38.  
  39. else {
  40. x1 = (-(b)- sqrt(delta))/( 2 * a );
  41. x2 = (-(b)+ sqrt(delta))/( 2 * a );
  42. System.out.println("Delta = " +delta);
  43. System.out.println("X1 = " +x1);
  44. System.out.println("X2 = " +x2);
  45. }
  46. }}
  47. }
  48.  
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement