Question: Debug this java program. I really need this to be right can you double ckeck your answer please!!!!! /* * Debugging Exercise * * the
Debug this java program.
I really need this to be right can you double ckeck your answer please!!!!!
/* * Debugging Exercise * * the error(s) * NOTE: This program prints six random numbers for a lotto ticket (five * numbers and a power ball). * * [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. One is a logic * error that produces invalid output. */
import java.util.Random; import java.util.ArrayList;
public class DebugMeTwo {
static ArrayList
public static void main(String[] args) { generateNumbers(); printNumbers(); }
private static void generateNumbers() { int ticketNumber; Random generateRandomNumber = new Random();
for (int count = 0; count < MAX_NUMBERS; count++) { ticketNumber = 1 + generateRandomNumber.nextInt(59); lottoNumbers.add(new Integer(ticketNumber)); } }
private static void printNumbers() { int count = 0; for( Integer number : numbers ) // enhanced for loop { if (count < 5) if (count == 4) System.out.print(number); else System.out.print(number + ", "); else { System.out.println(" Power Ball: " + number); count++; } } } }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
