Quantcast
Channel: Recent Questions - Stack Overflow
Viewing all articles
Browse latest Browse all 16030

Comparing elements in a array using equalities (Java) slot machine

$
0
0

So what im trying to do is take the randomly generated elements in my array and commpare them to make sure all three are the same.

import java.util.Scanner;import java.util.Random;public class Main {    public static void main(String[] args) {        Scanner scnr = new Scanner(System.in);        int slots[] = new int[3];        Boolean play = true;        String playAgain;        System.out.println("Welcome to the Simple Slot Machine!");        System.out.println("Press Enter to spin the wheels...");        Reel(slots);    }    public static void Reel(int[] slots) {        Random rand = new Random();        int num1 = 0;        int num2 = 0;        int num3 = 0;        int i;        for( i = 0; i < slots.length; i++) {            slots[i] = rand.nextInt(10);           }        num1 = slots[0];        num2 = slots[1];        num3 = slots[2];        if (num1 == num2 && num2 == num3) {            System.out.print(slots[i] +"... you win");        }        else if (num1 != num2) {            System.out.print(slots[i] +"... you lose");        }    }}

So far I've been able to get it to randomly generate numbersand I've figured out how to attach one of each three elements to three variablesbut once I make the condition where if num1 not equal to num2 the code breaks

i need it to say 777... WINNER! or 546... LOSER!wanna get this working before i work on the loop


Viewing all articles
Browse latest Browse all 16030

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>