用while语句打印阶乘

import java.util.Scanner;
public class Whilejc {
	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		System.out.println("欢迎使用求阶乘计算器,请输入一个整数");
		int a = s.nextInt();
		int d = a;
		int b = a-1;
		int c = a*b;
		while(b>1) {
			
			a = b;
			b--;
			c= c*b;
			
		}
		System.out.println(d+"的阶乘是"+c) ;
	}
}

 

posted @ 2019-08-03 10:19  水果、、  阅读(354)  评论(0编辑  收藏  举报