Java_03 for statement
package my;
public class _5For循环 {
public static void main(String[] args) {
// For循环
/* for语句的基本形式:
for (E1;E2;E3)
{
S1
}
E1:初始化表达式
E2:前置表达式(循环条件判断)
E3:后置表达式
S1:循环体*/
//计算1到100的平方之和
int total = 0;
int i;
for (i=1;i<=100;i++)
//也可以这样写
//for (int i=1;i<=100;i++)
{
total += i*i;
}
System.out.println("结果为 " + total);
//大家可以试着写一下for循环与if混合使用
}
}
Results of the: