package practiceGO; /* * 2.输出1+2+3....+100的和 */ public class Cto { public static void main(String[] args) { int result = 0; System.out.println("1+2+3+...+100的和为:"); for(int i=1; i<=100; i++){ result += i; } System.out.println(result); } }
运行:
1+2+3+...+100的和为: 5050