public class lab7 { public static void main(String[] args) { ConsoleReader console = new ConsoleReader(System.in); System.out.print("\nInput a value for X: "); double x = console.readDouble(); System.out.print("\nInput the value for N: "); int n = console.readInt(); System.out.println("For X = "+ x + " and n = " + n); double ex = calculate_ex(x,n); System.out.println("The final calculated value for e^x is: "+ ex); System.out.println("The True value for e^x is: "+ Math.pow(Math.E,x)); } // end main public static double calculate_ex(double x, int n) { double total = 0; double Factorial = 0; //debug//System.out.println("e^x = " + x + "^" + n); for(int i = 0; i<=n; i++) { Factorial = fact(i); total = total + (Math.pow(x,i)/Factorial); System.out.println("The estimated value for e^x when n = " + i + " is: " + total); //System.out.println("\tMath.pow("+x+","+i+")/"+Factorial + "\tTotal: " + total); } return total; } public static int fact(int k) { int factorial = 1; for(int j = 0; j<=k; j++) { if((j == 0)||(j == 1)) { factorial = 1; } else { factorial = factorial * j; } } return factorial; } } // end class