class JieChen
{
public static void main(String[] args)
{
for ( int i = 1; i<=10 ; i++ )
{
String str = ""; //定义一个字符串,收集字符串形式的阶乘表达式
int num = 1; //定义一个累乘器,收集阶乘数值
int k = i;
System.out.print(i + "!=");
for ( int j = i; j>0 ; j-- )
{
num *= j;
if (j==1)
{
str = j + "" +"\n";
}
else
{
str = j + "*";
} //当i=1是,后面没有*号,用if语句筛选
System.out.print(str);
}
System.out.println(k + "的阶乘是" + num);
System.out.println();
}
}
}
|
|