JAVA

Sunday, October 30, 2005

Homework 10/24/2005

import javax.swing.JOptionPane;
public class exponential{public static void main(String[] args){
String nString = JOptionPane.showInputDialog("Enter the number of n:(n=10,50,100)");
int n = Integer.parseInt(nString);
String xString = JOptionPane.showInputDialog("Enter the number of x:");
int x = Integer.parseInt(xString);
double all = 1, sum1 = 1, sum2 = 1;
for(int j=1;j<=n;j++)
{sum1 = sum1 * x;
sum2 = sum2 * j;
all = all + (sum1/sum2);
}
System.out.println("1+"+ x +"/1!+"+ x +"^"+ x +"/2!+.......answer="+all);
System.exit(0);
}
}









代表圖1
代表圖2
代表圖3

0 Comments:

Post a Comment

<< Home