zl程序教程

您现在的位置是:首页 >  其他

当前栏目

Groovy简单再入门

入门 简单 Groovy
2023-09-27 14:28:45 时间

以前试过,忘得差不多了,趁这次从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)]

}