当前位置: 代码迷 >> J2SE >> 循环话语for
  详细解决方案

循环话语for

热度:40   发布时间:2016-04-23 22:37:49.0
循环语句for
import java.util.Scanner;                           
import java.math.BigInteger;                        
public class T5                                     
{                                                   
public static void main(String[] args)            
{                                                 
int a;                                          
int b=1;                                        
System.out.println("请输入要求阶乘的数:");      
Scanner sc=new Scanner(System.in);              
a=sc.nextInt();                                 
BigInteger d=BigInteger.valueOf(1);             
do                                              
{                                               
d=d.multiply(BigInteger.valueOf(b));          
b++;                                          
}while(b<=a);                                 
System.out.println("所求的数的阶乘是:"+d);    
}                                               
}                                                 
  相关解决方案