1

Here is my code:

package misc;
/**
*
* @author cian
*/
import java.util.Random;
import java.util.Scanner;
public class Lotto_Project 
{
public static void main(String[] args) 
{
    Scanner keyboard = new Scanner(System.in);
    int jackpot;

    String[] players = {"Adam", "Ben", "David", "Emma"};
    int[][] numbers = {{2,12,4,6,},{14,1,5,10},{9,6,16,19},{2,18,16,15}};

    System.out.println("Please enter the jackpot amount:");
    jackpot = keyboard.nextInt();

    System.out.println("The jackpot amount is "+jackpot+".\n");

    int[] winNum;
    winNum = generateWinNum();

    System.out.println("The winning numbers are: "); 
    displaywinNum(winNum);

    System.out.print("\n"); 

    displayPlayer(players, numbers);



}

public static int[] generateWinNum()
{
    Random rand = new Random();
    int[] list = new int[4];

    for (int i = 0; i < 4; i++) 
    {
        list[i] = 1 + rand.nextInt(20);
    }
    return list;
}

public static void displaywinNum(int num[])
{
    for (int i = 0; i < num.length; i++)
    {
        System.out.print(num[i]+"\t"); 
    }
}

public static void displayPlayer(String[] players, int[][] numbers)
{       
    Scanner keyboard = new Scanner(System.in);
    System.out.println("Please enter the player's name:");
    String player1 = keyboard.nextLine();

    for (int i = 0; i < 4; i++)
    {
        if (players[i].equals(player1))
        {
            System.out.println("Your player is "+players[i]+"."); 
            System.out.println(players[i]+"'s numbers are "+numbers[i]+".");
        }

    }

}

}

For the output I get the following:

Please enter the jackpot amount:
100
The jackpot amount is 100.
The winning numbers are: 
3   6   3   3   
Please enter the player's name:
Emma
Your player is Emma.
Emma's numbers are [I@3d4eac69.

As you can see everything is working fine except the last line, where it says Emma's numbers are [I@3d4eac69.

I would like it to say:

Emma's numbers are 2,18,16,15.

Thanks in advance.

helencrump
  • 1,351
  • 1
  • 18
  • 27
Cian OT
  • 53
  • 1
  • 1
  • 7
  • Arrays.toString(numbers[i]); I'm sure you can find other questions for this too. This is similar to your display win number method. – matt Apr 12 '16 at 22:13
  • 1
    http://stackoverflow.com/questions/409784/whats-the-simplest-way-to-print-a-java-array – matt Apr 12 '16 at 22:14

0 Answers0