Advertisement
Vladkoheca

CalcThePowerOfANum.java

Oct 25th, 2024
9
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.54 KB | Source Code | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class CalcThePowerOfANum {
  4.     public static void main(String[] args) {
  5.         Scanner sc = new Scanner(System.in);
  6.  
  7.         System.out.print("Enter the base number: ");
  8.         int base = sc.nextInt();
  9.         System.out.print("Enter the exponent number: ");
  10.         int exponent = sc.nextInt();
  11.         int result = 1;
  12.         for (int i = 1; i <= exponent; i++) {
  13.             result *= base;
  14.         }
  15.         System.out.println(base + " to the power of " + exponent + " is: " + result);
  16.     }
  17. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement