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);
}
}
}
对于这个代码,我想要用for语句表达,怎么表示啊?我是卡在那个for(a;b;c)这里不知道怎么写,a是初始语句,b是跳出的语句,c是循环语句,java
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);
}
}
}
对于这个代码,我想要用for语句表达,怎么表示啊?我是卡在那个for(a;b;c)这里不知道怎么写,a是初始语句,b是跳出的语句,c是循环语句,java
解决方案 »
- String 数组比较 抛出异常
- 求助急急 急
- 在jsp页面中,讲鼠标变成小手
- 讨论:doGet,doPost等方法传进去的request,response到底是什么类型,迷惑!!!!!
- 关于用tomcat 5.0.x+sqlserver2000+jdbc for sqlserver2000数据库连接池的配置问题。谢谢
- 关于java进程的问题
- poi在weblogic和jbuilderx的配置?
- jb做出的项目编译成了exe文件,可是。。。
- 哪里有Weblogic的技术资料
- 泛型问题
- 循环 查找,判断问题
- 求助!急!com.microsoft.sqlserver.jdbc.SQLServerException: 该连接已关闭。
{
a*=a;
}
System.out.print(a);
public static void main (String [] args) { long f = 1;
for (int i = 1; i <= 10; i++) {
f = f * i;
//System.out.println("f=" + f);
}
System.out.println("f=" + f); //求n!
}
}
给楼主个小的测试下。看行不,可能有许多错误
for{int b=1;b<a+1;b++}{
d=d.multiply(BigInteger.valueOf(b));
}
System.out.println("所求的数的阶乘是:"+d);
其实for循环里面的a、b、c不用全写,用不到就可以不写嘛,如果都不写的话,就是while循环了···
希望我理解的没错。
...
}另外do while循环里的语句至少执行一次,所以要在for loop之前先写一遍那些语句。
这个練習应该是告诉你,何种情况下用do while循环比较好。