码迷,mamicode.com
首页 > 其他好文 > 详细

Groovy简单再入门

时间:2016-05-31 22:33:48      阅读:218      评论:0      收藏:0      [点我收藏+]

标签:

  以前试过,忘得差不多了,趁这次从JAVA一直撸到SERVLET,SPRING,GROOVY,GRAILS的机会,再弄一次吧。。。

 

def authors = [
    "Peter Ledbrook",
    "Glen Smith"
]

def quoteParts = [
    ["Time", "waits", "for no man"],
    ["The roundhouse kick", "solves", "all problems"],
    ["Groovy", "is", "the bees knees"]
]

for (i in 0..10) {
    def quote = createQuote(quoteParts, authors)
    println quote
}

String createQuote(List quoteParts, List authors) {
    def rand = new Random()
    def n = quoteParts.size()
    def m = authors.size()
    
    return quoteParts[rand.nextInt(n)][0] + ‘ ‘ +
        quoteParts[rand.nextInt(n)][1] + ‘ ‘ +
        quoteParts[rand.nextInt(n)][2] + ‘ by ‘ +
        authors[rand.nextInt(m)]
} 

技术分享

Groovy简单再入门

标签:

原文地址:http://www.cnblogs.com/aguncn/p/5547582.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!