Didart

Math Power

Oct 7th, 2021
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.67 KB | None | 0 0
  1. import java.text.DecimalFormat;
  2. import java.util.Scanner;
  3.  
  4. public class MathPower {
  5.     public static void main(String[] args) {
  6.         Scanner scanner = new Scanner(System.in);
  7.  
  8.         double num = Double.parseDouble(scanner.nextLine());
  9.         int power = Integer.parseInt(scanner.nextLine());
  10.  
  11.         double output = mathPower(num, power);
  12.  
  13.         DecimalFormat df = new DecimalFormat("0.####");
  14.  
  15.         System.out.println(df.format(output));
  16.     }
  17.  
  18.     public static double mathPower(double num, int power) {
  19.         double result = 1;
  20.         for (int i = 0; i < power; i++) {
  21.             result *= num;
  22.         }
  23.         return result;
  24.     }
  25. }
  26.  
Advertisement
Add Comment
Please, Sign In to add comment