62,628
社区成员
发帖
与我相关
我的任务
分享

package helloWorld;
public class Test{
public static void main(String[] args) {
int n=1;
int i=1;
do {
n*=2;
//System.out.println("这是第"+i+"次执行!"); //本行显示第几次执行do循环体
//System.out.println("n="+n); //本行显示本次循环执行后的结果
i++;
}while(i<10);
System.out.println(n);
System.out.println("循环一共执行了"+(i-1)+"次!");
}
}
运行结果
我还是习惯用for写
package helloWorld;
public class Test{
public static void main(String[] args) {
int n=1;
for(int i=1;i<=9;i++) {
n*=2;
}
System.out.println(n);
}
}