10 回答
TA贡献4条经验 获得超8个赞
public class test { public static void main(String[] args) { int total = sum(1,1000); System.out.println(total); } public static int sum(int start, int end) { int total = 0; start = 1; while (start <= end) { total += start; start++; } return total; } }
public class test { public static void main(String[] args) { int total = 0; int i = 1; while (i <= 1000) { total += i; i++; } System.out.println(total); } }
TA贡献140条经验 获得超197个赞
public class Test { public static void main(String[] args) { int sum = 0; for (int i = 1; i <= 1000; i++) { sum += i; } System.out.println(sum); } }
代码以上,望采纳。
TA贡献17条经验 获得超11个赞
public class while_1 { public static void main(String[] args) { int i=1;//从i开始 int sum=0;//表示和 int j=1000;//到j结束 while(i<=j){ sum=sum+i; i++; } System.out.println(sum); }
TA贡献10条经验 获得超4个赞
//while var sum=0; var i = 1; while(i<=1000){ sum+=i; ++i; } console.log(sum); alert(sum);
//for var sum = 0; for(int i = 1; i <= 1000; i++) { sum += i; }
TA贡献217条经验 获得超353个赞
public class Test11 { public static void main(String[] args) { int i = 1, n = 0; while (i <= 1000) {// 如何用while循环计算1至1000之和,并将之和赋值给变量? n = (i == 1000) ? (System.out.printf("1+2+……+100=%d", n += i++) != null ? n : 0) : (n + i++); } } }
TA贡献1条经验 获得超0个赞
public class test{
public static void main(String[]args){
int i=1;
int sum=0;
while(i<=1000){
sum=i+sum;
i++;
}
System.out.println("1+2+3+...+1000的和是:"+sum);
}
}
TA贡献5条经验 获得超1个赞
public void test2() {
int start = 1;
int end = 1000;
int total = 0;
while (start <= end) {
total += start;
start++;
}
System.out.println(total);
}
TA贡献5条经验 获得超2个赞
function sum(num) {
var result = 0;
var i = 1;
while (i <= num) {
result += i;
i++;
}
return result;
}
sum(1000);
TA贡献452条经验 获得超796个赞
public class Calculate{
public static void main(String[] args)
{
int sum = 0;
int i=1;
while(i<=1000)
{
sum+=i;
++i;
}
System.out.println(sum);
}
}
添加回答
举报