这是我的代码:
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]+".");
}
}
}
}
对于输出,我得到以下内容:
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.
正如你所看到的,除了最后一行之外,一切都正常,Emma's numbers are [I@3d4eac69
。
我想说:
Emma's numbers are 2,18,16,15.
提前致谢。