Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Christian
- {
- public static void main(String[] args)
- {
- Scanner input = new Scanner(System.in);
- System.out.print("Enter a number x to compute e^x: ");
- int x = input.nextInt();
- System.out.print("Enter a Number of Terms: ");
- double n = input.nextDouble();
- double sum = 0;
- for(int i = 0; i < n; ++i)
- {
- sum += (Math.pow(x, i))/factorial(i);
- }
- System.out.print(sum);
- }
- public static double factorial(double n)
- {
- int ret = 1;
- for (double i = 1.0; i <= n; ++i) ret *= i;
- return ret;
- }
- }
Add Comment
Please, Sign In to add comment