标签:
以前试过,忘得差不多了,趁这次从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)] }
标签:
原文地址:http://www.cnblogs.com/aguncn/p/5547582.html