import java.util.*; public class Methods1 { public static void main(String[] args) { Random r = new Random(); boolean result = seven(r); System.out.println(); System.out.println("result = " + result); System.out.println("sum = " + digitSum(12345)); } // returns the sum of the digits of n (assumes n is not negative) public static int digitSum(int n) { int sum = 0; while (n > 0) { int digit = n % 10; n = n / 10; sum += digit; } return sum; } // generates up to 10 numbers between 1 and 30 stopping if the "lucky // number" 7 comes up and returning whether or not that happened public static boolean seven(Random r) { for (int i = 1; i <= 10; i++) { int next = r.nextInt(30) + 1; System.out.print(next + " "); if (next == 7) { return true; } } return false; } // variation of the seven method that generates exactly 10 numbers between // 1 and 30 and that returns whether or not the "lucky number" 7 comes up // among the 10 numbers public static boolean seven2(Random r) { boolean seen7 = false; for (int i = 1; i <= 10; i++) { int next = r.nextInt(30) + 1; System.out.print(next + " "); if (next == 7) { seen7 = true; } } return seen7; } }