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.         BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
  2.        
  3.         int num;
  4.         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.         BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
  5.        
  6.         int num;
  7.         int power;
  8.        
  9.         System.out.print("Enter a number:");
  10.         num = Integer.parseInt(in.readLine());
  11.         System.out.print("Enter an exponent:");
  12.         power = Integer.parseInt(in.readLine());
  13.        
  14.        
  15.         System.out.print("The answer is:" + Math.pow(num,power));
  16.         }
  17.        
  18. }
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