標題:
402-尾端遞迴階乘計算
[打印本頁]
作者:
許承鴻
時間:
2018-7-24 18:26
標題:
402-尾端遞迴階乘計算
import java.util.Scanner;
public class JPD04 {
static Scanner keyboard = new Scanner(System.in);
public static void main(String args[]) {
...
}
}
作者:
張閎鈞
時間:
2018-8-7 20:05
import java.util.Scanner;
public class JPD04 {
static Scanner keyboard = new Scanner(System.in);
public static void main(String args[]) {
System.out.print("Inpu n <0<=n<=16>:");
int a=keyboard.nextInt();
int b=1;
int g=f(a,b);
System.out.print(f(a,b));
}
static int f(int a,int b)
{
if(a==1)
{
return b;
}
else
{
return f(a-1,a*b);
}
}
}
複製代碼
作者:
巫晉宇
時間:
2018-8-7 20:09
package ghh;
import java.util.Scanner;
public class sgg {
static Scanner k = new Scanner(System.in);
public static void main(String[] args){
int w=k.nextInt();
int y=f(w,1);
System.out.print(y);
}
static int f(int w,int e)
{
if(w==0)
{
return w;
}
else
{
return f(w-1,w*e);
}
}
}
作者:
巫沛庭
時間:
2018-8-7 20:13
import java.util.Scanner;
public class JPA04 {
static Scanner keyboard = new Scanner(System.in);
public static void main(String args[]) {
System.out.print("Input n(0<=n<=16)");
int num=keyboard.nextInt();
int g=f(num,1);
System.out.print(num+"的階乘: "+g);
}
static int f(int k,int r)
{
if(k==0)
{
return r;
}
else{
return f(k-1,r*k);
}
}
}
複製代碼
歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://seed.istak.org.tw/)
Powered by Discuz! 7.2