求n的阶乘(while循环版)

package hello;

import java.util.Scanner;

public class Hello {

 public static void main(String[] args) {
  Scanner in = new Scanner(System.in);
  int n;
  n=in.nextInt();
  int i=1,sum=1;
  while(i<=n)
  {
   sum=sum*i;
   i++;
  }
  System.out.print(sum);
 }

}

你可能感兴趣的:(Java,java)