2005/10/31

Lab 10-31 (1) product of N positive numbers

product of N positive numbers
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
public class lab1031 {
public lab1031() {
}

public static void main(String[] args)throws IOException {
BufferedReader keyboard =new BufferedReader(new InputStreamReader(System.in));
System.out.println("Please enter the negtive numbers");
System.out.println("Enter a positive number to exit");

int product=1;
String nextString = keyboard.readLine();
int next = Integer.parseInt(nextString.trim());
while(next>=0)
{
product=product*next;
nextString = keyboard.readLine();
next = Integer.parseInt(nextString.trim());
}
System.out.println("product is "+product);
}
}

10-31 Quiz Fibonacci


Cows
Bees
Rabbits




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 &&amp ; 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);
}
}