Question: /* * Debugging Exercise * Debug the error(s) * Please do not submit if it is not debugged * * NOTE: This program prints six

/* * Debugging Exercise * Debug the error(s) * Please do not submit if it is not debugged * * NOTE: This program prints six random numbers for a lotto ticket (five * numbers and a power ball). * There is a "ArrayIndexOutOfBounds" error that you need to debug. * [there is no check for duplication of lotto numbers for the ticket] * * The output should display as follows: * * 55, 31, 57, 46, 20 * Power Ball: 24 * * HINT: There are two lines that require debugging. */ import java.util.Random; import java.util.ArrayList; public class DebugMeOne {

static int[] lottoNumbers = new int[6];

public static void main(String[] args) { generateNumbers(); printNumbers(); }

private static void generateNumbers() { int ticketNumber; Random generateRandomNumber = new Random();

for (int count = 0; count < lottoNumbers.length + 1; count++) { ticketNumber = 1 + generateRandomNumber.nextInt(59); lottoNumbers[count] = ticketNumber; } }

private static void printNumbers() { for (int count = 0; count < lottoNumbers.length + 1; count++) { if (count < 5) if (count == 4) System.out.print(lottoNumbers[count]); else System.out.print(lottoNumbers[count] + ", "); else System.out.println(" Power Ball: " + lottoNumbers[count]); } } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!