Advertisement
Guest User

Untitled

a guest
Jun 19th, 2019
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1. package mocnina;
  2. import java.util.Scanner;
  3. /**
  4. *
  5. * @author Filip
  6. */
  7. public class Mocnina {
  8.  
  9. /**
  10. * @param args the command line arguments
  11. */
  12. public static void main(String[] args) {
  13. System.out.println ("Zadej číslo ");
  14. Scanner sc1 = new Scanner (System.in);
  15. int cislo = sc1.nextInt();
  16. System.out.println ("zadej mocninu");
  17. Scanner sc2 = new Scanner (System.in);
  18. int moc = sc2.nextInt();
  19. System.out.println(umocni(cislo, moc));
  20.  
  21. }
  22. public static int umocni (int cislo, int moc){
  23. int pomocna = cislo;
  24. if (moc == 0){
  25. return 1;
  26. }
  27. else{
  28. for (int i = 1; i < moc; i++){
  29. cislo = cislo * pomocna;
  30. }
  31. return cislo;
  32. }
  33. }
  34.  
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement