求任意數字的階乘

ThinkPet發表於2018-03-15
package cube;

import java.util.Scanner;


public class JieCheng {
	 int JieCheng() {
		System.out.println("輸入數字n");
		Scanner scanner=new Scanner(System.in);
		int n=Integer.parseInt(scanner.nextLine());
		int j=1;
		for(int i=1;i<=n;i++){
			j*=i;
			
		}
		return j;
		
	}

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		JieCheng j1=new JieCheng();
		
		System.out.println("所求階乘結果為"+j1.JieCheng());
		

	}

}

相關文章