Groovy实例计算1到100的和


package com.happy.operator

/**
* @author: (le.qiao)
* @e-mail: [email protected]
* @myblog: http://qiaolevip.iteye.com
* @date: 2012-8-24
*
*/
public class Sum100 {
public static void main(def args){
// 1..100相加之和(5050)
def sum = 0;1.upto(100){sum+=it};println(sum);
// 1..1000相加之和(500500)
sum = 0;1.upto(1000){sum+=it};println(sum);
}
}

你可能感兴趣的:(Groovy,乔乐共享,groovy,sum)