public class jiecheng{
創(chuàng)新互聯(lián)從2013年開始,是專業(yè)互聯(lián)網(wǎng)技術(shù)服務(wù)公司,擁有項目網(wǎng)站制作、成都網(wǎng)站建設(shè)網(wǎng)站策劃,項目實施與項目整合能力。我們以讓每一個夢想脫穎而出為使命,1280元霍州做網(wǎng)站,已為上家服務(wù),為霍州各地企業(yè)和個人服務(wù),聯(lián)系電話:18982081108
static int Run(int n){
if(n==1){
return n;
}else{
return n*Run(n-1);
}
}
public static void main(String[] args){
int n = 5;
int result = 0;
result = Run(5);
System.out.println(result);
}
}
用于你只是求5的階乘,所以沒必要弄得那么麻煩,不用對被階乘數(shù)進行判斷。當(dāng)然可以更加復(fù)雜一點。
public class Demo{
public static void main(String[] args){
int a = 5;
int result = 1;
for(int i = 1;i = a; i ++){
result *= a;
}
System.out.println("5!的結(jié)果是: " + result);
}
}
最簡單的計算:5×4×3×2×1
public static void main(String[] args){
System.out.println(5×4×3×2×1);
}
復(fù)雜點通用的
public static int get(int n){
if(n==1){
return n;
}else{
return n*get(n-1);
}
}
public static void main(String[] args){
System.out.println(get(5));
}
分享標題:關(guān)于5的階乘java代碼的信息
URL網(wǎng)址:http://m.kartarina.com/article34/hegope.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供響應(yīng)式網(wǎng)站、做網(wǎng)站、網(wǎng)站設(shè)計公司、、電子商務(wù)、建站公司
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)