// Marty Stepp, CSE 142, Spring 2010 // This program plays a simple "lotto" game that draws up to ten lottery numbers, // each from 1-30. If it gets a lucky 7, it stops. // The method returns true/false based on whether it found a 7 or not. // The purpose of this program is to practice methods with loops that return. import java.util.*; public class LuckySeven { public static void main(String[] args) { Random rand = new Random(); // play 3 rounds of lotto seven(rand); System.out.println(); seven(rand); System.out.println(); seven(rand); System.out.println(); } // Draws 10 lotto numbers 1-30; returns true if one is 7. // 15 29 18 29 11 3 30 17 19 22 (first call) // 29 5 29 4 7 (second call) public static boolean seven(Random rand) { for (int i = 1; i <= 10; i++) { int lotto = rand.nextInt(20) + 1; System.out.print(lotto + " "); if (lotto == 7) { return true; } } return false; } }