TheBulgarianWolf

Number_Power

Apr 2nd, 2020
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.65 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3.  
  4.  
  5. public class SoftUni {
  6.  
  7.     static int calculatePower(int num,int pow){
  8.         int result = 1;
  9.         for(int i = 0;i<pow;i++){
  10.             result *= num;
  11.         }
  12.         return result;
  13.     }
  14.    
  15.     public static void main(String[] args){
  16.         Scanner sc = new Scanner(System.in);
  17.        
  18.         System.out.print("Enter your number: ");
  19.         int num = Integer.parseInt(sc.nextLine());
  20.         System.out.print("Enter the power of the number: ");
  21.         int power = Integer.parseInt(sc.nextLine());
  22.         int result = calculatePower(num, power);
  23.         System.out.println(result);
  24.     }
  25.    
  26. }
Add Comment
Please, Sign In to add comment