Advertisement
Guest User

Untitled

a guest
Nov 21st, 2019
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 8.66 KB | None | 0 0
  1. public class Homework {
  2.  
  3.     private static double func(double x) {
  4.         return x*x+3;
  5.         }
  6.    
  7.     public static void main(String[] args) {
  8.        
  9.         Przykl1 przykl1 = new Przykl1();
  10.         Przykl2 przykl2 = new Przykl2();
  11.         Przykl3 przykl3 = new Przykl3();
  12.         Zad1 zad1 = new Zad1(-3,-2,-1);
  13.         Zad2 zad2 = new Zad2(5,-2,0);
  14.         Zad3 zad3 = new Zad3(4);
  15.         Zad4 zad4 = new Zad4(0.01);  
  16.         Zad5 zad5 = new Zad5(0.01);
  17.        
  18.     }
  19.  
  20. }
  21. class Przykl1      
  22. {
  23.     public Przykl1()
  24.     {
  25.         int a=0;
  26.         if(a>=10)
  27.         {System.out.println("Prawda");}
  28.         else
  29.         {System.out.println("Fałsz");}
  30.        
  31.     }
  32. }
  33.  
  34. class Przykl2
  35. {
  36.    
  37.     public Przykl2()
  38.     {
  39.         int a = 15;
  40.         switch(a)
  41.         {
  42.             case 15: {System.out.println("Opcja pierwsza");} break;
  43.             case 25: {System.out.println("Opcja druga");} break;
  44.             default: {System.out.println("Brak opcji");}
  45.         }
  46.     }
  47. }
  48.  
  49. class Przykl3
  50. {
  51.     public Przykl3()
  52.     {
  53.            int licznik=0, zakres=10;
  54.            System.out.println("Petla while");
  55.            while(licznik < zakres) {System.out.println(licznik); licznik++;}
  56.            
  57.            licznik = 0;
  58.            System.out.println("Petla do-while");
  59.            do
  60.                 {System.out.println(licznik); licznik++;}
  61.            while(licznik < zakres);
  62.            
  63.            System.out.println("Petla for");
  64.            for(licznik=0; licznik < zakres; licznik++)
  65.            {
  66.                System.out.println(licznik);
  67.            }
  68.     }
  69. }
  70.  
  71. class Zad1
  72. {
  73.     public Zad1(int a, int b, int c)
  74.         {
  75.            if(a>b)
  76.            {
  77.                if(a>c)
  78.                {
  79.                    System.out.println("Najwieksza: "+a);
  80.                }
  81.                else System.out.println("Najwieksza: "+c);
  82.            }
  83.            else if(b>c)
  84.            {
  85.                System.out.println("Najwieksza: "+b);
  86.            }
  87.            else System.out.println("Najwieksza: "+c);
  88.         }
  89. }
  90.  
  91.  
  92. class Zad2
  93. {
  94.     public Zad2(float a, float b, float c)
  95.         {
  96.             float delta = (b*b) -(4*a*c);
  97.                        
  98.             System.out.println("Delta = "+delta);
  99.             if(delta<0)
  100.             {
  101.                 System.out.println("Brak rozwiazan");
  102.             }
  103.             else if(delta==0)
  104.             {
  105.                 float roz0 = -b/2*a;
  106.                 System.out.println("1 rozwiazanie: "+roz0);
  107.             }
  108.             else
  109.             {
  110.                 float pierwiastek = (float)Math.sqrt(delta);
  111.                 float roz1 = (-b-pierwiastek)/(2*a);
  112.                 float roz2 = (-b+pierwiastek)/(2*a);
  113.                
  114.                 System.out.println("2 rozwiazania: "+roz1+" i "+roz2);
  115.             }
  116.         }
  117. }
  118.  
  119. class Zad3
  120. {
  121.     public Zad3(int n)
  122.     {
  123.    
  124.               int p,r=n;    
  125.               int s=n;
  126.               while(r>0)
  127.               {
  128.                   p=4;
  129.                
  130.                 while(p>0)
  131.                 {
  132.                      System.out.print('*');
  133.                      p--;  
  134.                 }
  135.                 System.out.println();
  136.                 r--;
  137.               }
  138.               System.out.println();
  139.              
  140.               for(int i=0; i<n; i++)
  141.               {
  142.                       for(int j=0; j<n; j++)
  143.                       {
  144.                           System.out.print('*');
  145.                       }
  146.               System.out.println();
  147.               }
  148.               System.out.println();
  149.               do
  150.               {                            
  151.                 int o=n;
  152.                
  153.                 do
  154.                 {                    
  155.                  System.out.print('*');
  156.                  o--;
  157.                 }while(o>0);      
  158.                  s--;  
  159.               System.out.println();
  160.               }while(s>0);
  161.               ////////////////////////////////////////
  162.               System.out.println();
  163.               p=0;
  164.              
  165.               while(p<n)
  166.               {
  167.                   s=0;
  168.                   while(s<=p)
  169.                   {
  170.  
  171.                       System.out.print('*');
  172.                       s++;
  173.                   }
  174.                   System.out.println();
  175.                   p++;
  176.               }
  177.               System.out.println();
  178.               for(int i=0; i<n; i++)
  179.               {
  180.                       for(int j=0; j<=i; j++)
  181.                       {
  182.                           System.out.print('*');
  183.                       }
  184.                       System.out.println();
  185.               }
  186.               System.out.println();
  187.               p=0;
  188.              
  189.               do
  190.               {    
  191.                 s=0;
  192.                 do
  193.                 {                    
  194.                  System.out.print('*');
  195.                  s++;
  196.                 }while(s<=p);      
  197.               System.out.println();
  198.               p++;
  199.               }while(p<n);
  200.              
  201.               //////////////////////////////////////////
  202.               System.out.println();
  203.               p=0;
  204.               while(p<n)
  205.               {
  206.                   r=0;
  207.                   s=0;
  208.                   while(r<=(n-(p+1)))
  209.                   {
  210.                       System.out.print(' ');    
  211.                       r++;
  212.                   }
  213.                   while(s<(p+1))
  214.                       {
  215.                       System.out.print('*');
  216.                       s++;
  217.                       }
  218.                   System.out.println();
  219.                   p++;
  220.               }
  221.                            
  222.               System.out.println();
  223.               for(int i=0; i<n; i++)
  224.               {
  225.                   for(int j=0; j<=(n-(i+1)); j++)
  226.                   {
  227.                       System.out.print(' ');                
  228.                   }
  229.                   for(int k=0; k<(i+1); k++) System.out.print('*');
  230.                   System.out.println();
  231.               }
  232.               System.out.println();
  233.               p=0;
  234.               do
  235.               {
  236.                   r=0;
  237.                   s=0;
  238.                   do
  239.                   {
  240.                      System.out.print(' ');    
  241.                      r++;
  242.                   }while(r<=(n-(p+1)));
  243.                   do
  244.                   {
  245.                      
  246.                       System.out.print('*');
  247.                       s++;   
  248.                   }while(s<(p+1));
  249.                  
  250.                   System.out.println();
  251.                   p++;
  252.               }while(p<n);
  253.               /////////////////////////////////////////////
  254.               System.out.println();
  255.              
  256.               p=0;
  257.               while(p<=n)
  258.               {
  259.                   r=0;
  260.                   s=0;
  261.                   while(r<=(n-(p+1)))
  262.                   {
  263.                       System.out.print(' ');    
  264.                       r++;
  265.                   }
  266.                   while(s<(2*p)-1)
  267.                       {
  268.                       System.out.print('*');
  269.                       s++;
  270.                       }
  271.                   System.out.println();
  272.                   p++;
  273.               }
  274.               System.out.println();
  275.               for(int i=1; i<=n; i++)
  276.               {
  277.                   for(int j=0; j<=(n-(i+1)); j++)
  278.                   {
  279.                       System.out.print(' ');                
  280.                   }
  281.                   for(int k=0; k<((2*i)-1); k++) System.out.print('*');
  282.                   System.out.println();
  283.               }
  284.               System.out.println();
  285.               p=1;
  286.               do
  287.               {
  288.                   r=0;
  289.                   s=0;
  290.                   do
  291.                   {
  292.                      System.out.print(' ');                                  
  293.                      r++;
  294.                   }while(r<=(n-p));
  295.                   do
  296.                   {  
  297.                        System.out.print('*');
  298.                       s++;   
  299.                   }while(s<(2*p)-1);
  300.                  
  301.                   System.out.println();
  302.                   p++;
  303.               }while(p<=n);        
  304.      }
  305.  
  306. }
  307.  
  308.  
  309. class Zad4
  310. {
  311.     public Zad4(double dx) {
  312.    
  313.     int xp,xk;
  314.     double calka;
  315.    
  316.     xp = -2;    //to argumenty dla ktorych y = 4 przecina f(x)
  317.     xk = 2;
  318.        
  319.     calka = 0;
  320.     for(int i=1; i<=((xk-xp)/dx); i++)
  321.     {
  322.         calka += func(xp + (double)i*dx);
  323.        
  324.     }
  325.     calka *= dx;
  326.    
  327.     System.out.println("Wartość całki wynosi w przybliżeniu " + calka);
  328.     }
  329.    
  330.     private static double func(double x)
  331.    
  332.         {
  333.         return x*x;
  334.         }
  335. }
  336.  
  337. class Zad5
  338. {
  339.     public Zad5(double dx)
  340.     {
  341.         int xp,xk;
  342.         double calka;
  343.        
  344.         xp = 0;     //to argumenty dla ktorych y = 2x przecina f(x)
  345.         xk = 4;
  346.                
  347.         calka = 0;
  348.         for(int i=1; i<=((xk-xp)/dx); i++)
  349.         {
  350.             calka += func(xp + (double)i*dx);
  351.            
  352.         }
  353.         calka *= dx;
  354.        
  355.         System.out.println("Wartość całki wynosi w przybliżeniu " + calka);
  356.         }
  357.        
  358.         private static double func(double x)
  359.        
  360.             {
  361.             return x*x;
  362.             }
  363. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement