admin 管理员组

文章数量: 1086019


2024年3月13日发(作者:摩托车select是什么意思)

1. 使用while循环,求1+11+111+1111+11111+111111。

public class Test {

public static void main(String[] args) {

int i = 0;

double n = 0;

double sum = 0;

while(i<6){

n = n+Math.

pow

(10,i);

sum =sum+n;

i++;

}

System.

out

.println("1+11+111+1111+11111+111111="+sum);

}

}

2. 求10的阶乘 1x2x3x4…x10.

public class Test {

public static void main(String[] args) {

int result = 1;

for(int i = 10;i > 0;i--){

result *= i;

}

System.

out

.println("10!="+result);

}

}

3. 求1+2+3……+1000的和,把和输出,计算每步结果中有多少个最后以8结尾的。

public class Test {


本文标签: 输出 循环 计算 使用 结果