Advertisement
veronikaaa86

08. Math Power

Oct 6th, 2021
315
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.69 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 num = Double.parseDouble(scanner.nextLine());
  11. int power = Integer.parseInt(scanner.nextLine());
  12.  
  13. double output = mathPower(num, power);
  14.  
  15. DecimalFormat df = new DecimalFormat("0.####");
  16.  
  17. System.out.println(df.format(output));
  18. }
  19.  
  20. public static double mathPower(double num, int power) {
  21. double result = 1;
  22. for (int i = 0; i < power; i++) {
  23. result *= num;
  24. }
  25.  
  26. return result;
  27. }
  28. }
  29.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement