Lab 1-02-2006 Recursion
package hk;
import java.io.*;
public class sh {
public static double recursive(double number) {
if (number == 0)
return 0;
else if (number == 1) {
return 1;
}
else return (number * recursive(number - 1));
}
public static void main(String[] args) throws IOException {
double n;
BufferedReader keyboard = new BufferedReader(new InputStreamReader(System.
in));
System.out.println("please type positive number");
String input = keyboard.readLine();
double temp = Double.parseDouble(input.trim());
n = recursive(temp);
System.out.println(temp + "!=" + n);
}
}
import java.io.*;
public class sh {
public static double recursive(double number) {
if (number == 0)
return 0;
else if (number == 1) {
return 1;
}
else return (number * recursive(number - 1));
}
public static void main(String[] args) throws IOException {
double n;
BufferedReader keyboard = new BufferedReader(new InputStreamReader(System.
in));
System.out.println("please type positive number");
String input = keyboard.readLine();
double temp = Double.parseDouble(input.trim());
n = recursive(temp);
System.out.println(temp + "!=" + n);
}
}
0 Comments:
張貼留言
<< Home