Advertisement
Guest User

Untitled

a guest
Nov 24th, 2014
197
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.10 KB | None | 0 0
  1. import java.io.*;
  2. public class TrojmianKwadratowy {
  3.     static byte ileMiejscZerowych(int a,int b,int c){
  4.         double delta=b*b-4*a*c;
  5.         if(delta>0){
  6.             return 2;
  7.         }else if(delta==0){
  8.             return 1;
  9.         }else{
  10.             return 0;
  11.         }
  12.     }
  13.     static boolean maMaksimum(int a){
  14.         if(a>0){
  15.             return true;
  16.         }else{
  17.             return false;
  18.         }
  19.     }
  20.     static double ekstremum(int a,int b,int c){
  21.         int q=-(b*b-4*a*c)/(4*a);
  22.         return q;
  23.     }
  24.     static double wartoscTrojmianu(int a,int b,int c, int arg){
  25.         return a*arg*arg+b*arg+c;
  26.     }
  27.     static boolean czyParzysta(int a,int b,int c){
  28.         int p=-(b/(2*a));
  29.         if(p==0){
  30.             return true;
  31.         }else{
  32.             return false;
  33.         }
  34.     }
  35.     public static void main(String[] args) {
  36.         Console k1=System.console();
  37.         int a=Integer.parseInt(k1.readLine("Podaj liczbe calkowita "));
  38.        
  39.         Console k2=System.console();
  40.         int b=Integer.parseInt(k2.readLine("Podaj liczbe calkowita "));
  41.        
  42.         Console k3=System.console();
  43.         int c=Integer.parseInt(k3.readLine("Podaj liczbe calkowita "));
  44.        
  45.         Console k4=System.console();
  46.         int arg=Integer.parseInt(k4.readLine("Podaj punkt dla ktorego chcesz obliczyc wartosc trojmianu "));
  47.        
  48.         System.out.println("Trojmian kwadratowy o podanych wspolczynnikach ma nastepujaca liczbe miejsc serowych " + ileMiejscZerowych(a, b, c));
  49.         if(maMaksimum(a)==true){
  50.         System.out.println("ma wartosc maksymanla, ");
  51.         }else{
  52.             System.out.println("nie ma wartosci maksymalnej, ");
  53.         }
  54.         System.out.println("ekstremum jest rowne: " + ekstremum(a, b, c));
  55.         System.out.println("wartosc trojmianu w podanym punkcie wynosi: " + wartoscTrojmianu(a, b, c, arg));
  56.         if(czyParzysta(a, b, c)==true){
  57.             System.out.println("trojmian jest funkcja parzysta.");
  58.         }else{
  59.             System.out.println("trojmian nie jest funkcja przysta.");
  60.         }
  61.     }
  62.    
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement