public class W { public static void main(String[] args) {
int X=1;
int S=0;
if(X<=100){
X=X++;
S= S+X;
}else{
System.out.println(S);
}
} }
这是我写的 但是在eclipse里什么都没有输出,哪里错了还是怎么回事??

解决方案 »

  1.   

    if 就没有走。你嘚while 吧 
      

  2.   

    public class test { public static void main(String[] args) {
    int s = 0;
    for (int i = 1; i <= 100; i++) {
    s = s + i;
    }
    System.out.println(s);
    }}
      

  3.   

    if只会走一遍while(X<=100)这样
      

  4.   

    你写的代码只会执行if代码块而不会执行else里的代码。可以利用for循环来实现你要的功能
      

  5.   

    int X=1;
    int S=0;
    while(X<=100){
    S+=X;
        X++;
    }
    System.out.println(S);
      

  6.   


    能啊 只是你把输出句放在了else里面 而这个条件满足了if 就只做if里面的语句 所以输出放在if里面 else 后面可以写 System.out.println("出错了");