package Scanner; //while循环语句 public class While { public static void main(String[] args) { int a = 0; int sum = 0; while (a <= 5){ sum = (sum + a); a++; System.out.println(a+"===="+sum); } //计算1+2+3+4+5的和 System.out.println(a); System.out.println(sum); } } 输出结果:
1====0
2====1
3====3
4====6
5====10
6====15
6
15