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;
}
}
Aya Safi
0
Newbie Poster
Recommended Answers
Jump to PostLine 10 you calculate Math.pow(x, i); but you don't do anything with the result.
All 3 Replies
Aya Safi
0
Newbie Poster
JamesCherrill
4,733
Most Valuable Poster
Team Colleague
Featured Poster
Tarek_2
commented:
This answer resolves the problem.
+0
jwenting
1,889
duckman
Team Colleague
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.