Java局部变量

2019年2月11日21:18:17 发表评论 944 views
/**
 * Created by xabcd on 2019/2/11.
 */
public class TestJava4_4
{public static void main(String[]args)
{
    int sum = 0;
    for(int i=1;i<=5;i++)
    {
        sum = sum + i;
        System.out.println("i=" + i + ", sum =" + sum);
    }
    //i是局部变量
}
}





i=1, sum =1
i=2, sum =3
i=3, sum =6
i=4, sum =10
i=5, sum =15

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: