标签:OLE pre 应用程序 最大 lang 循环语句 一个 for for循环
int sum = 0;
int fac = 1;
for (int i = 1; i <= 10; i++) {
//求阶乘
for (int j = 1; j <= i; j++) {
fac *= j;
}
sum += fac;
fac = 1;
}
System.out.println("1!+2!+...+10!= " + sum); //4037913
for(int i = 1; i < 101; i++){
boolean flag = i!=1;
for (int j = 2; j < i; j++){
if (i%j == 0){
flag = false;
break;
}
}
if (flag){
System.out.println(i);
}
}
//do-while循环
int i = 1;
double sum = 0;
do{
int j = 1;
int fac = 1;
//求分母的阶乘
do{
fac *= j;
j++;
}while(j <= i);
sum += 1.0 / fac;
i++;
}while(i <= 20);
System.out.println(sum); //1.7182818346494484
//for循环
double sum = 0;
for (int i = 1; i <= 20; i++) {
int fac = 1;
for (int j = 1; j <= i; j++) {
fac *= j;
}
sum += 1.0/fac;
}
System.out.println(sum); //1.7182818346494484
for (int i = 1; i < 1000; i++) {
int sum = 0;
for (int j = 1; j < i; j++) {
if (i%j == 0){
sum += j;
}
}
if (sum == i){
System.out.println(i); //6 28 496
}
double num = 0;
double sum = 0;
for (int i = 0; i < 10; i++) {
if (i == 0){
num = 8;
}else {
//num = num + (8 * Math.pow(10,(double)i));
//实现8 * Math.pow(10,(double)i)
double temp = 8;
for (int j = 1; j <= i; j++) {
temp *= 10;
}
num += temp;
}
sum += num;
}
System.out.println(sum); //9.8765432E9
int sum = 0;
int n = 0;
for ( ; sum < 8888; n++) {
sum += n;
}
System.out.println(n); //134
标签:OLE pre 应用程序 最大 lang 循环语句 一个 for for循环
原文地址:https://www.cnblogs.com/weifengfuzhi/p/14828410.html