Free Data Structures and Algorithms Course

Subscribe below and get all best seller courses for free !!!


Subscribe to all free courses

How to calculate Exponential of a number through a Java program ?.

Program to demonstrate how to calculate Exponential of a number in Java.

Click here to download complete source code

package com.hubberspot.code;

import java.util.Scanner;

public class ExponentialCalculation {

 public static void main(String[] args) {

  // Create a Scanner object which will read 
  // values from the console which user enters
  Scanner scanner = new Scanner(;

  // Getting input from user from the console
  System.out.println("Enter value of number ");

  // Calling nextDouble method of scanner for
  // taking a double value from user and storing
  // it in number variable
  double number = scanner.nextDouble();


  System.out.println("Calculating exponential of a number ... ");

  // In order to calculate exponential of a number 
  // we use Math class exp() static method which takes in a 
  // number and returns back the exponential of a number
  double result = Math.exp(number);

  // printing the result on the console
  System.out.println("Exponential of " + number + " is : " + result); 



Click here to download complete source code

Output of the program :

© 2021 Learn Java by Examples Template by Hubberspot