Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
mbrock add sample script aeaf412 Nov 29, 2007
0 contributors

Users who have contributed to this file

38 lines (28 sloc) 747 Bytes
/**
* Sample MVEL 2.0 Script
* "Random Guess"
* by: Christopher Michael Brock
*/
import java.io.*;
//
// Seed the random number
//
$num = (int) Math.random() * 100;
$guesses = 0;
$in = -1;
//
// Setup the STDIN line reader.
//
$linereader = new BufferedReader(new InputStreamReader(System.in));
System.out.print("I'm Thinking of a Number Between 1 and 100... Can you guess what it is? ");
//
// Main program loop
//
while ($in != $num) {
if ($in != -1) {
System.out.print("Nope. The number is: " + ($num < $in ? "Lower" : "Higher") + ". What's your next guess? ");
}
if (($in = $linereader.readLine().trim()) == empty) $in = -2;
$guesses++;
}
System.out.println("You got it! It took you " + $guesses + " tries");
You can’t perform that action at this time.