import java.util.Scanner; public class FactorialTest { public static void main(String args[]) { System.out.println("请输入数字n"); while (true) { Scanner input = new Scanner(System.in); double n = input.nextDouble(); double sum = 1; double i = 1; for (i = 1; i <= n; i++) { sum *= i;} System.out.println("for的阶乘n=" + sum); i = 1; sum = 1; while (i <= n) { sum *= i; i++;} System.out.println("while的阶乘n= " + sum); sum=1; i=1; do { sum *= i; i++; }while (i <= n); System.out.println("do的阶乘n=" + sum); } } }
第7周作业1-循环大战
最新推荐文章于 2022-10-31 21:46:47 发布