1-10内的数字累加,输出和大于20的数字。

package ch06;

/**
 * Created by liwenj on 2017/7/18.
 */
public class test6 {
    public static void main(String[] args) {
        int total = 0;
        int i = 0;
        for (; i < 10; i++) {
            total = total + i;//取值在循环内,和放应该到循环里面
            if (total > 20) {
                System.out.println(i);
                break;
            }

        }

    }

}
原文地址:https://www.cnblogs.com/lwj820876312/p/7199341.html