数组只打印参考?

时间:2015-03-31 03:39:38

标签: java arrays

我目前正在创建一个像老虎机一样工作的程序,用户可以编写" Spin"然后它以数组的形式生成一些随机数,然后打印出来供用户查看。问题是我可以弄清楚如何打印出数组,以便以后可以用来查找匹配项 这是迄今为止的代码:

public static int listofNums(int NUM_VALS)  {
    NUM_VALS=3;
    Random rn=new Random();
    int[] list=new int[NUM_VALS];
    int i=0;
    list[0]=rn.nextInt(10);
    list[1]=rn.nextInt(10);
    list[2]=rn.nextInt(10);

    for(i=0;i<NUM_VALS-1;i++){
        System.out.print(list[i]+" ");
    }
return list[i];
}
public static int addPoints(int numMatches){
    int score=50;
    numMatches=0;
    switch (numMatches) {
        case 1: numMatches=0;
            score=score-1;
            System.out.println("Sorry, you lost 1 point.");
            break;
        case 2: numMatches=2;
            score=score+5;
            System.out.println("You gained 5 points!");
            break;
        case 3: numMatches=3;
            score=score+20;
            System.out.println("You gained 20 points!");
        case 4: numMatches=4;
            score=score+750;
            System.out.println("Jackpot! You gained 750 points!");
    }
    return score;
}       

public static void main(String[] args) {
    final int NUM_VALS=3;
    int[] list=new int[listofNums(3)];
    int[] newList; 
    newList=list;
    boolean stop=false;
    String command;
    Scanner scnr=new Scanner(System.in);
    System.out.println("Welcome to high stakes slot!");
    System.out.println("Type 'Spin' to spin the wheel, type 'Stop' to see hoe much youve won!");

    while(!stop)    {
        command=scnr.next();
        if (command.equals("Spin"))     {
            System.out.println(newList[0]); }

当我运行该程序时,会打印出类似这样的内容:

Welcome to high stakes slot! Type 'Spin' to spin the wheel, type 'Stop' to see hoe much youve won! Spin 0 Spin 0

我不知道自己做错了什么,非常感谢帮助!非常感谢你。

更新:在查看给我的内容以查看是否重复之后,我的问题与其他主题中所说的内容之间的区别是: - 我使用随机数生成我的数组,以及必须通过对方法进行引用来实现,即,我不能在声明的数组的后面放置一个括号。或者我认为。

更新:我已经删除了打印出的参考文献,但现在它只是在用户&#34;旋转&#34;时打印出来。

0 个答案:

没有答案
相关问题