exponential
import javax.swing.*;
public class exponential
{
public static void main(String[] args)
{
double sum = 0;
int n = 1;
double z = 1 ;
String input = JOptionPane.showInputDialog("Enter a number") ;
int inputNumber = Integer.parseInt(input);
for (int j = 1 ; j <=10;j++)
{
n = j * n;
z = inputNumber*z;
sum =sum+ (z/n);
System.out.print(n+" ,");
System.out.print(z+" ,");
System.out.println(sum+" ,");
}
System.out.print("The 10 factorial = "+n+" ,");
System.out.print("The X^10 ="+z+" ,");
sum =sum+1;
System.out.println("Sum = "+sum);
// System.out.println(sum);
}
}
Homework Fibonacci Numbers
package Hw5;
/**
*
9224205 江昇祐
*
*
ibonacci numbers.
List the first 100 numbers and the ratio of
a number to its previous number.
*
*
Copyright: Copyright (c) 2006
*
*
CYCUIE
*
*/
public class fibonacci {
public static void main(String[] args) {
double firstNumber = 0;
double secondNumber = 1 ;
double thirdNumber = 0 ;
double ratio = 0 ;
for (int i = 2 ; i<100; i++)
{
if(i==2){
System.out.println("f0 = " + firstNumber+"the ratio =" + ratio);
System.out.println("f1 = " + secondNumber+"the ratio =" + ratio);
}
thirdNumber= firstNumber+secondNumber ;
ratio = thirdNumber/secondNumber;
System.out.println("f"+i+" = "+thirdNumber+ "the ratio =" + ratio);
firstNumber = secondNumber;
secondNumber=thirdNumber ;
}
}
}