Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
import java.util.Scanner;
/**
* Performs integer exponentiation with a user-specified base and exponent.
*
* Rachel Szivos
*/
public class PowerCalculator {
public static void main(String []args){
// prompt the user and read input
System.out.print("Enter two integers (base and exponent): ");
Scanner in = new Scanner(System.in);
int base= in.nextInt();
int exp = in.nextInt();
// calculate result
int result = (int) Math.pow(base, exp);
// format and display result
String output = base + "^" + exp + " is " + result;
System.out.println(output);
}
}
Advertisements
We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.
AcceptLearn more