Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

/* * 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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Online Systems For Physicians And Medical Professionals How To Use And Access Databases

Authors: Harley Bjelland

1st Edition

1878487442, 9781878487445

More Books

Students also viewed these Databases questions