Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Witaj {
- public static void main(String[] args) {
- System.out.println("Jak masz na imię");
- Scanner src = new Scanner(System.in);
- String imie = src.nextLine();
- System.out.println("Mam na imię " + imie);
- src.close();
- }
- }
- ________
- import java.util.Scanner;
- public class Arytmetyczna {
- public static void main(String[] args) {
- System.out.println("Poda a: ");
- Scanner src = new Scanner(System.in);
- byte a = src.nextByte();
- System.out.println("Poda b: ");
- byte b = src.nextByte();
- System.out.println(a +" / " + b + " = " + a/b + " * " + b +" +" + a%b);
- }
- }
- _____
- public class Rekurencja {
- public static int ile = 0;
- public static int ile1 = 0;
- public static int ile2 = 0;
- public static int sumka(int n)
- {
- ile++;
- if( n == 1)
- {
- return 1;
- }
- else
- {
- return sumka(n-1) + n;
- }
- }
- public static int potega(int a, int b)
- {
- ile1++;
- if(b ==1 )
- {
- return a;
- }
- else
- {
- return potega(a, b - 1) * a;
- }
- }
- public static int fibek(int n)
- {
- ile2++;
- if(n == 1 | n == 2)
- {
- return 1;
- }
- else
- {
- return fibek(n-2) + fibek(n-1);
- }
- }
- }
- ________
- public class Glowna {
- public static void main(String[] args) {
- System.out.println(CechaPodzielnosci.PodzeilnoscPrzez3(971));
- System.out.println(Rekurencja.sumka(123) + "\t liczba wywołań: " + Rekurencja.ile);
- System.out.println(Rekurencja.potega(2,6) + "\t liczba wywołań: " + Rekurencja.ile1);
- System.out.println(Rekurencja.fibek(40) + "\t liczba wywołań: " + Rekurencja.ile2);
- }
- }
- __________
- public class CechaPodzielnosci {
- public static String PodzeilnoscPrzez3(int a)
- {
- if(a % 3 == 0)
- {
- return a + " jest podzielne przez 3";
- }
- else
- {
- return a + " nie jest podzielne przez 3";
- }
- }
- }
Add Comment
Please, Sign In to add comment