Groovy简单再入门

  以前试过,忘得差不多了,趁这次从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简单再入门_第1张图片

你可能感兴趣的:(Groovy简单再入门)