wozniol

Java #1

Apr 8th, 2022 (edited)
28
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.88 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Witaj {
  4.  
  5.     public static void main(String[] args) {
  6.         System.out.println("Jak masz na imię");
  7.         Scanner src = new Scanner(System.in);
  8.         String imie = src.nextLine();
  9.         System.out.println("Mam na imię " + imie);
  10.         src.close();
  11.     }
  12.  
  13.  
  14. }
  15.  
  16.  
  17.  
  18. ________
  19.  
  20.  
  21. import java.util.Scanner;
  22.  
  23. public class Arytmetyczna {
  24.  
  25.     public static void main(String[] args) {
  26.         System.out.println("Poda a: ");
  27.         Scanner src = new Scanner(System.in);
  28.         byte a = src.nextByte();
  29.  
  30.         System.out.println("Poda b: ");
  31.         byte b = src.nextByte();
  32.        
  33.         System.out.println(a +" / " + b + " = " + a/b + " * " + b +" +" + a%b);
  34.  
  35.     }
  36.  
  37. }
  38.  
  39.  
  40.  
  41. _____
  42.  
  43.  
  44. public class Rekurencja {
  45.     public static int ile = 0;
  46.     public static int ile1 = 0;
  47.     public static int ile2 = 0;
  48.    
  49.     public static int sumka(int n)
  50.     {
  51.         ile++;
  52.         if( n == 1)
  53.         {
  54.             return 1;
  55.         }
  56.         else
  57.         {
  58.             return sumka(n-1) + n;
  59.         }
  60.     }
  61.    
  62.     public static int potega(int a, int b)
  63.     {
  64.         ile1++;
  65.         if(b ==1 )
  66.         {
  67.             return a;
  68.         }
  69.         else
  70.         {
  71.             return potega(a, b - 1) * a;
  72.         }
  73.     }
  74.    
  75.     public static int fibek(int n)
  76.     {
  77.         ile2++;
  78.         if(n == 1 | n == 2)
  79.         {
  80.             return 1;
  81.         }
  82.         else
  83.         {
  84.             return fibek(n-2) + fibek(n-1);
  85.         }
  86.     }
  87. }
  88.  
  89. ________
  90.  
  91.  
  92. public class Glowna {
  93.     public static void main(String[] args) {
  94.         System.out.println(CechaPodzielnosci.PodzeilnoscPrzez3(971));
  95.        
  96.         System.out.println(Rekurencja.sumka(123) + "\t liczba wywołań: " + Rekurencja.ile);
  97.         System.out.println(Rekurencja.potega(2,6) + "\t liczba wywołań: " + Rekurencja.ile1);
  98.         System.out.println(Rekurencja.fibek(40) + "\t liczba wywołań: " + Rekurencja.ile2);
  99.     }
  100. }
  101.  
  102. __________
  103.  
  104.  
  105. public class CechaPodzielnosci {
  106.     public static String PodzeilnoscPrzez3(int a)
  107.     {
  108.         if(a % 3 == 0)
  109.         {
  110.             return a + " jest podzielne przez 3";
  111.         }
  112.         else
  113.         {
  114.             return a + " nie jest podzielne przez 3";
  115.         }
  116.     }
  117. }
  118.  
Add Comment
Please, Sign In to add comment