Hyluss

Funkcja kwadratowa

Feb 28th, 2017
722
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.28 KB | None | 0 0
  1. /**
  2.  * Created by Hylus on 2017-02-28.
  3.  */
  4.  
  5. import java.util.Scanner;
  6.  
  7. public class organizacyjne
  8. {
  9.     public static void main( String[] args)
  10.     {
  11.         System.out.printf("y=ax^2 + bx + c\n");
  12.         System.out.printf("Podaj a b c x1 x2 dx\n"); //x1 i x2 to zakres, dx co ile ma sie zmieniac
  13.  
  14.         Scanner input = new Scanner (System.in);
  15.         double a = input.nextDouble();
  16.         double b = input.nextDouble();
  17.         double c = input.nextDouble();
  18.  
  19.         double delta = (b*b)-(4*a*c);
  20.         if (delta>0) {
  21.  
  22.             double x2;
  23.             double x1;
  24.  
  25.             x1 = input.nextDouble();
  26.             do {
  27.                 x2 = input.nextDouble();
  28.             } while (x2 < x1);
  29.  
  30.             double dx = input.nextDouble();
  31.  
  32.             System.out.printf("Reprezentuje funkcje: y=%.2f*x^2+%.2f*b + %.2f\n", a, b, c);
  33.             System.out.printf("Miejsca zerowe to %.2f i %.2f\n", (-b - Math.sqrt(delta)) / (2 * a), (-b + Math.sqrt(delta)) / (2 * a));
  34.  
  35.             System.out.printf("\tX\t|\tY\n");
  36.             for (double i = x1; i <= x2; i = i + dx) {
  37.                 System.out.printf("%.2f\t|\t%.2f\n", i, a * (i * i) + b * i + c);
  38.             }
  39.         }
  40.         else
  41.         {
  42.             System.out.printf("delta < 0");
  43.         }
  44.  
  45.     }
  46. }
Advertisement
Comments
  • User was banned
Add Comment
Please, Sign In to add comment