Advertisement
Alan468

Java Lab_00

Feb 28th, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.55 KB | None | 0 0
  1. package Lab;
  2.  
  3. import java.util.*;
  4.  
  5. public class Lab {
  6.  
  7.     Scanner in;
  8.     float a,b,c;
  9.     float x1,x2,dx,delta;
  10.     float xa,xb;
  11.    
  12.     public Lab() {
  13.         in = new Scanner(System.in);
  14.        
  15.         System.out.print("Podaj a: ");
  16.         a = in.nextFloat();
  17.         System.out.print("Podaj b: ");
  18.         b = in.nextFloat();
  19.         System.out.print("Podaj c: ");
  20.         c = in.nextFloat();
  21.        
  22.         System.out.print("Podaj x1: ");
  23.         x1 = in.nextFloat();
  24.         System.out.print("Podaj x2: ");
  25.         x2 = in.nextFloat();
  26.        
  27.         System.out.print("Podaj dx: ");
  28.         dx = in.nextFloat();
  29.        
  30.         delta = (float) (Math.pow(a, 2) - 4*a*c);
  31.        
  32.         System.out.format("Postać równania %.1fx^2 + %.1fx + %.1f\n",a,b,c);
  33.         System.out.format("Wypisanie wartosci od %.2f do %.2f z skokiem %.2f\n",x1,x2,dx);
  34.        
  35.         if(delta>=0){
  36.             xa = (float)(b+Math.sqrt(delta))/2*a;
  37.             System.out.format("xa = %.2f\n",xa);
  38.             if(delta>0){
  39.                 xb = (float)(b-Math.sqrt(delta))/2*a;
  40.                 System.out.format("xa = %.2f\n",xb);
  41.             }
  42.         }
  43.        
  44.         System.out.format("====================\n");
  45.         System.out.format("| %6s | %6s |\n","X","Y");
  46.         for(float i=x1;i<x2;i++){
  47.             System.out.format("| %6.2f | %6.2f |\n",i,(a*(i*i)+(b*i)+c));
  48.         }
  49.         System.out.format("====================\n");
  50.        
  51.     }
  52.    
  53.     public static void main(String[] args) {
  54.         new Lab();
  55.     }
  56.    
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement