import java.util.Scanner;
import java.lang.Math;
public class Exercise1 {
    public static void main(String[] args){
        double x,sum = 0.0 ;
        Scanner scan = new Scanner(System.in);
        System.out.print("Enter the number : ");
        x = scan.nextInt();
        for(double i=0;i<=(x+1);i++){
            Math.pow(x, i);
            fact(i);
            double y = (Math.pow(x, i)/fact(i));
            sum += y;
        }
        System.out.println("The e^"+x+" for "+x+" is :"+sum);
    }
  public static double fact(double i ){
      double val;
      if(i == 0){
          val = 1;}
          else{
    val = i*fact(i-1);}
      return val;
}
}

the programm doesn't return an accurate value for e^x i don't know why ... any help

Line 10 you calculate Math.pow(x, i); but you don't do anything with the result.

commented: This answer resolves the problem. +0

floating point == rounding errors...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.