Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Homework {
- private static double func(double x) {
- return x*x+3;
- }
- public static void main(String[] args) {
- Przykl1 przykl1 = new Przykl1();
- Przykl2 przykl2 = new Przykl2();
- Przykl3 przykl3 = new Przykl3();
- Zad1 zad1 = new Zad1(-3,-2,-1);
- Zad2 zad2 = new Zad2(5,-2,0);
- Zad3 zad3 = new Zad3(4);
- Zad4 zad4 = new Zad4(0.01);
- Zad5 zad5 = new Zad5(0.01);
- }
- }
- class Przykl1
- {
- public Przykl1()
- {
- int a=0;
- if(a>=10)
- {System.out.println("Prawda");}
- else
- {System.out.println("Fałsz");}
- }
- }
- class Przykl2
- {
- public Przykl2()
- {
- int a = 15;
- switch(a)
- {
- case 15: {System.out.println("Opcja pierwsza");} break;
- case 25: {System.out.println("Opcja druga");} break;
- default: {System.out.println("Brak opcji");}
- }
- }
- }
- class Przykl3
- {
- public Przykl3()
- {
- int licznik=0, zakres=10;
- System.out.println("Petla while");
- while(licznik < zakres) {System.out.println(licznik); licznik++;}
- licznik = 0;
- System.out.println("Petla do-while");
- do
- {System.out.println(licznik); licznik++;}
- while(licznik < zakres);
- System.out.println("Petla for");
- for(licznik=0; licznik < zakres; licznik++)
- {
- System.out.println(licznik);
- }
- }
- }
- class Zad1
- {
- public Zad1(int a, int b, int c)
- {
- if(a>b)
- {
- if(a>c)
- {
- System.out.println("Najwieksza: "+a);
- }
- else System.out.println("Najwieksza: "+c);
- }
- else if(b>c)
- {
- System.out.println("Najwieksza: "+b);
- }
- else System.out.println("Najwieksza: "+c);
- }
- }
- class Zad2
- {
- public Zad2(float a, float b, float c)
- {
- float delta = (b*b) -(4*a*c);
- System.out.println("Delta = "+delta);
- if(delta<0)
- {
- System.out.println("Brak rozwiazan");
- }
- else if(delta==0)
- {
- float roz0 = -b/2*a;
- System.out.println("1 rozwiazanie: "+roz0);
- }
- else
- {
- float pierwiastek = (float)Math.sqrt(delta);
- float roz1 = (-b-pierwiastek)/(2*a);
- float roz2 = (-b+pierwiastek)/(2*a);
- System.out.println("2 rozwiazania: "+roz1+" i "+roz2);
- }
- }
- }
- class Zad3
- {
- public Zad3(int n)
- {
- int p,r=n;
- int s=n;
- while(r>0)
- {
- p=4;
- while(p>0)
- {
- System.out.print('*');
- p--;
- }
- System.out.println();
- r--;
- }
- System.out.println();
- for(int i=0; i<n; i++)
- {
- for(int j=0; j<n; j++)
- {
- System.out.print('*');
- }
- System.out.println();
- }
- System.out.println();
- do
- {
- int o=n;
- do
- {
- System.out.print('*');
- o--;
- }while(o>0);
- s--;
- System.out.println();
- }while(s>0);
- ////////////////////////////////////////
- System.out.println();
- p=0;
- while(p<n)
- {
- s=0;
- while(s<=p)
- {
- System.out.print('*');
- s++;
- }
- System.out.println();
- p++;
- }
- System.out.println();
- for(int i=0; i<n; i++)
- {
- for(int j=0; j<=i; j++)
- {
- System.out.print('*');
- }
- System.out.println();
- }
- System.out.println();
- p=0;
- do
- {
- s=0;
- do
- {
- System.out.print('*');
- s++;
- }while(s<=p);
- System.out.println();
- p++;
- }while(p<n);
- //////////////////////////////////////////
- System.out.println();
- p=0;
- while(p<n)
- {
- r=0;
- s=0;
- while(r<=(n-(p+1)))
- {
- System.out.print(' ');
- r++;
- }
- while(s<(p+1))
- {
- System.out.print('*');
- s++;
- }
- System.out.println();
- p++;
- }
- System.out.println();
- for(int i=0; i<n; i++)
- {
- for(int j=0; j<=(n-(i+1)); j++)
- {
- System.out.print(' ');
- }
- for(int k=0; k<(i+1); k++) System.out.print('*');
- System.out.println();
- }
- System.out.println();
- p=0;
- do
- {
- r=0;
- s=0;
- do
- {
- System.out.print(' ');
- r++;
- }while(r<=(n-(p+1)));
- do
- {
- System.out.print('*');
- s++;
- }while(s<(p+1));
- System.out.println();
- p++;
- }while(p<n);
- /////////////////////////////////////////////
- System.out.println();
- p=0;
- while(p<=n)
- {
- r=0;
- s=0;
- while(r<=(n-(p+1)))
- {
- System.out.print(' ');
- r++;
- }
- while(s<(2*p)-1)
- {
- System.out.print('*');
- s++;
- }
- System.out.println();
- p++;
- }
- System.out.println();
- for(int i=1; i<=n; i++)
- {
- for(int j=0; j<=(n-(i+1)); j++)
- {
- System.out.print(' ');
- }
- for(int k=0; k<((2*i)-1); k++) System.out.print('*');
- System.out.println();
- }
- System.out.println();
- p=1;
- do
- {
- r=0;
- s=0;
- do
- {
- System.out.print(' ');
- r++;
- }while(r<=(n-p));
- do
- {
- System.out.print('*');
- s++;
- }while(s<(2*p)-1);
- System.out.println();
- p++;
- }while(p<=n);
- }
- }
- class Zad4
- {
- public Zad4(double dx) {
- int xp,xk;
- double calka;
- xp = -2; //to argumenty dla ktorych y = 4 przecina f(x)
- xk = 2;
- calka = 0;
- for(int i=1; i<=((xk-xp)/dx); i++)
- {
- calka += func(xp + (double)i*dx);
- }
- calka *= dx;
- System.out.println("Wartość całki wynosi w przybliżeniu " + calka);
- }
- private static double func(double x)
- {
- return x*x;
- }
- }
- class Zad5
- {
- public Zad5(double dx)
- {
- int xp,xk;
- double calka;
- xp = 0; //to argumenty dla ktorych y = 2x przecina f(x)
- xk = 4;
- calka = 0;
- for(int i=1; i<=((xk-xp)/dx); i++)
- {
- calka += func(xp + (double)i*dx);
- }
- calka *= dx;
- System.out.println("Wartość całki wynosi w przybliżeniu " + calka);
- }
- private static double func(double x)
- {
- return x*x;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement