package com58.bj.java; public class OddSum { /** * @param args * 用for循環 * 計算1+3+5+7+9+99 */ public static void main(String[] args) { long sum = 0; for (int i=1; i<=99; i=i+2){ sum = sum +i; } System.out.println("sum="+sum); //計算2+4+6+8+....+100 long result = 0; for (int i=2;i<=100;i+=2){ result += +i; } System.out.println("result="+result); } }