Lab exponential
Lab exponential
import javax.swing.JOptionPane;
public class Labexponential {
public static double fac(int n)
{
double Num = 1;
for(int i=1;i<=n;i++)
{ Num = Num*i; }
return Num;
}
public static double sqrt(int x,int n)
{
double X = 1;
for(int i=1;i<=n;i++)
{ X = X*x; }
return X;
}
public static void main(String[] args)
{
double exp = 1;
int n = 0;
do{
String n_str = JOptionPane.showInputDialog("Enter the number for n(n=10,50,100) :");
n = Integer.parseInt(n_str);
}
while(n!=10 && ; n!=50 && n!=100);
String x_str = JOptionPane.showInputDialog("Enter the number of x:");
int x = Integer.parseInt(x_str);
for(int i=1;i<=n;i++)
{ exp = exp + ( sqrt(x,i) / fac(i) ); }
JOptionPane.showMessageDialog(null,"The value of Exponential " + x + " = " +exp);
System.exit(0);
}
}
0 Comments:
張貼留言
<< Home