0

I have to create a lottery simulator that shows six different, random numbers between one and 47. There's supposed to be three different methods, and one of them is specifically for printing out the numbers. I don't know how to get it to print multiple numbers. Note: I'm very new to programming so if you could explain how everything works in your answers it would help.

This is all I've gotten so far:

import java.util.*;

/**
* @author El
*/
public class Simulator {

/**
 * @param args
 */

public static final int NUM_OF_BALLS = 6;
public static final int MAX_VALUE_IN_BUCKET = 47;
public static final int SEED = 1;

public Random  numberGenerator = new Random ( SEED );   

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

private static void printWinners(){

}

}

2 Answers2

0

There are many ways to print out multiple numbers which seems to be your question. I assume that you want to print them out to the command line so you would need to use System.out.print(number) where you would just replace number with the number. To have more control formating how you want it to look use System.out.printf(format,args,...) You are wanting to print out six numbers so your formating may look like this "%d %d %d %d %d %d%n" where %d means that you are going to give it an integer. %n tells it to print a new line. The System.out.printf function is special in that it can take any number of arguments after the first so you would end up with a line of code looking something like this: System.out.printf("%d %d %d %d %d %d%n",number1,number2,number3,number4,number5,number6);

Legion
  • 796
  • 7
  • 12
0

It might be helpful to, as a new programmer, break down this problem into a few steps:

  1. Create a list, preferably an array of integers to hold your lottery numbers capable of holding all 6 digits. You should be able to discover how to do this.

  2. Generate a random number, between 1 and 47. How to do so can easily be found by Googling or looking around the Math class in Java.

  3. Check if this number is in your list, and act accordingly (if it's already in the list, repeat step 1). If not in the list, then add the list and sort it (hint: Arrays.sort(myArray))

  4. Repeat from step 0 until your array is FULL. In programming, repetition is usually achieved with a loop. In this case, a for-loop would be a good choice since you know ahead of time how many iterations you'll need (however many lottery numbers there are).

Kon
  • 10,702
  • 6
  • 41
  • 58