如何写用while语句来写从1加到100的整数和?

解决方案 »

  1.   

    不会是要这样吧?int m = 0;//存放最终结果
            int n = 0;
            while ((++n) <= 100)
            {
                m += n;
            }
      

  2.   

    //:用while实现1+到100
    public class TestWhile {
        public static void main(String[] arg){
            //最终结果N
         int n = 0 ;
         //使用M控制循环
         int m = 0 ;
         while (m <= 99) {
         n = ++n + m ;
         m++;
         }
         System.out.println("the note must to be" + n);
        }
    }///:~编译通过