thinkofanumber.groovy

来自「Groovy动态语言 运行在JVM中的动态语言 可以方便的处理业务逻辑变化大的业」· GROOVY 代码 · 共 22 行

GROOVY
22
字号
/** 
 * Simple game
 * @author: Jeremy Rayner
 * based on algorithms from INPUT/Marshall Cavendish/1984
 */
while (true) {
    try {
        int x = Math.random() * 6
        print "The computer has chosen a number between 0 and 5. Can you guess it?"
              
        def line = System.in.readLine()
        int g = line.toInteger()
        if (g == x) {
           println "Well done" 
        } else {
           println "Tough luck - you're wrong"
        }
     } catch (NumberFormatException e) {
         println "The computer didn't understand '$line'"
     }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?