Compute Exponent in Java

This tutorial will teach you how to create a program that will compute exponent in java. So, now let's start this tutorial! 1. Open JCreator or NetBeans and make a java program with a file name of powExponent.java. 2. Import the io package library:
  1. import java.io.*;
3. We will initialize variables in our Main, variable in for BufferedReader as our input, num and power as Integer.
  1.  
  2. int num;
  3. int power;
4. Now, we will have inputting for the base number and the exponent. Have the code below:
  1. System.out.print("Enter a number:");
  2. num = Integer.parseInt(in.readLine());
  3. System.out.print("Enter an exponent:");
  4. power = Integer.parseInt(in.readLine());
5. Lastly, we will display compute the exponential number using the Math.pow method.
  1. System.out.print("The answer is:" + Math.pow(num,power));
The Math.pow method has the following parameters of a base number and the exponent (basenumber,exponent). Then it will compute the exponential number. Output: output Here's the full code of this tutorial:
  1. import java.io.*;
  2. public class powExponent {
  3. public static void main(String args[]) throws IOException{
  4.  
  5. int num;
  6. int power;
  7.  
  8. System.out.print("Enter a number:");
  9. num = Integer.parseInt(in.readLine());
  10. System.out.print("Enter an exponent:");
  11. power = Integer.parseInt(in.readLine());
  12.  
  13.  
  14. System.out.print("The answer is:" + Math.pow(num,power));
  15. }
  16.  
  17. }
For more inquiries and need programmer for your thesis systems in any kind of programming languages, just contact my number below. Best Regards, Engr. Lyndon Bermoy IT Instructor/System Developer/Android Developer/Freelance Programmer Mobile: 09488225971 Landline: 826-9296 E-mail:[email protected] Add and Follow me on Facebook: https://www.facebook.com/donzzsky Visit and like my page on Facebook at: https://www.facebook.com/BermzISware

Add new comment