/* * 编写程序求 1+3+5+7+……+99 的和值 */ public class MarkDome { public static void main(String[] args) { int add = sum(99); System.out.println(add); System.out.println(sum(10)); } //累加方法 public static int sum(int num){ int sum =0; for(int x=1;x<=num;x++){ sum += x; } return sum; } }