Answer to Question #323983 in Java | JSP | JSF for stephanie

Question #323983

Create a static method

public static int pow(int base, int exp)

that returns the power value of base raised to its exponent. Use this method in a program that first asks for a base value and an exponent value, calls pow() and then prints the result.


Sample output:

Enter the base: 2

Enter the exponent: 3

The power value is 8




1
Expert's answer
2022-04-05T13:18:17-0400
import java.io.IOException;
import java.util.Arrays;
import java.util.Random;
import java.util.Scanner;

public class Main {

    public static int removeSpace(String str){
        str = str.replaceAll(" ", "");
        System.out.println(str);
        return str.length();
    }

    public static int[] Killed(int[] arrayDragon, Scanner in){
        int ch = in.nextInt();

        for (int i = 0; i < arrayDragon .length; i++) {
            if(ch == arrayDragon [i]){
                arrayDragon [i] = 0;
            }
        }
        return arrayDragon;
    }

    public static int pow(int base, int exp){
        int rez = 1;
        for(int i = 0; i < exp; i++)
            rez *= base;

        return rez;
    }

    public static void main(String[] args) throws IOException {
        Scanner in = new Scanner(System.in);
        System.out.print("Enter the base: ");
        int base = in.nextInt();
        System.out.print("Enter the exponent: ");
        int exp = in.nextInt();
        System.out.println("The power value is " + pow(base, exp));

    }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS