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.
Tutorialspoint

Power Calculator - Section 1

import java.util.Scanner;

/*
Performs integer exponention with a user-specified base and exponent.

@author Jake Nocentino
@version September 13, 2017
*/

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 results
        String output = base + "^" + exp + " is " + result;
        System.out.println(output);
    }
}

Advertisements
Loading...

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.