编写程序,计算1+2+3+…..+100的值
int a1=1;
int a2=2;
int a3=3;
int a100=100;
a100=a1+a2+....+a100;
语法
while(条件表达式){
循环体
}
class Demo{
public static void main(String[] args){
int counter = 1;
int sum = 0;
while(counter <= 100){
//sum = sum + counter;
sum += counter;
counter++;
}
System.out.println("1+2+....+100=" + sum);
}
}