Advertisement
veronikaaa86

08. Math Power

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