用java程序编写1+3+5+7+9+...+99的值
答案:4 悬赏:80 手机版
解决时间 2021-12-22 22:36
- 提问者网友:焚苦与心
- 2021-12-22 03:22
用java程序编写1+3+5+7+9+...+99的值
最佳答案
- 五星知识达人网友:狂恋
- 2021-12-22 03:45
public class test {
public static void main(String[] args) {
// TODO Auto-generated method stub
int sum = 0;
for(int i = 1; i < 100; i = i+2) {
sum = sum + i;
}
System.out.println(sum);
}
}
public static void main(String[] args) {
// TODO Auto-generated method stub
int sum = 0;
for(int i = 1; i < 100; i = i+2) {
sum = sum + i;
}
System.out.println(sum);
}
}
全部回答
- 1楼网友:鸽屿
- 2021-12-22 06:34
public static void main(String[] args) {
int total = 0;
for (int i = 1; i <= 99; i += 2)
total += i;
System.out.println(total);
}
- 2楼网友:想偏头吻你
- 2021-12-22 06:01
①:
public class total {
public static void main(string args[]) {
int sum = 0;
for(int i=1 ; i<=9; i = i+2){
int s = 0;
for(int j=1;j<=i;j++){
s=s+j*i;
}
sum = sum + s;
}
system.out.println(sum);
}
}
②:
1boolean
2for
3else
③:
1tvset
2getbrand()
3tvset
4string
5this.getbrand();
6string
7string
- 3楼网友:玩世
- 2021-12-22 05:11
public class Test {
public static void main(String args[]){
int x = 1;
int s = 0;
do{
s = s + x;
x = x + 2;
}while( x < 100 );
System.out.println("1+3+5+...+99= " + s );
}
}
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯