import java.io.BufferedReader;
import java.io.IOException; import java.io.InputStreamReader; public class FactorialTest { public static void main(String[] args) throws IOException{ BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); System.out.println("请输入N:"); double one = Integer.parseInt(in.readLine()); double sum=1; for(double i=1;i<=one;i++){ sum*=i; } System.out.println(one+"的阶乘"+sum); } }
for循环
while循环import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class FactorialTest { public static void main(String[] args) throws IOException{ BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); System.out.println("请输入N:"); int one = Integer.parseInt(in.readLine()); int sum=1; int i=1; while( i<=one){ sum*=i; i++; } System.out.println(one+"的阶乘"+sum); } }
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class FactorialTest { public static void main(String[] args) throws IOException{ BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); System.out.println("请输入N:"); int one = Integer.parseInt(in.readLine()); double sum=1; int i=1; do{ sum*=i; i++; }while(i<=one); System.out.println(one+"的阶乘是"+sum); } }
do-while循环
=。=没有按老师要求来做的,只是输出了特定的数回去再弄从1到n的
第7周作业1-循环大战
最新推荐文章于 2022-10-31 21:46:47 发布