# Thread: Roulette Wheel Quick Help

1. Member
Join Date
Oct 2012
Posts
5
Rep Power
0

## Roulette Wheel Quick Help

So, I've fairly far along on a project for school but would love some sort of direction. We haven't used arrays yet so I'd like to avoid using if possible but my question is the following. I've simulating 1000 rolls on the roulette wheel and need to give summary at the end of how many times it landed on red, black, odd and even. the problem is that 1-10 reds are odd numbers and black are even numbers; 11-20 reds are even and black are odd. I really don't want the answer but just a hint as to how I can arrange it to run like that. Obviously, I could write a bunch of if and elses but I would like to be as clever as possible in answering. thanks in advance.

Maybe I'm not that far along but here is what I'm at so far:

import java.util.Random;
import java.util.Scanner;

public class Roulette
{
public static void main(String[] args)
{
//Local declarations
Scanner keyboard = new Scanner(System.in);
Random generator = new Random();
int green=0;
int red=0;
int black=0;
int even=0;
int odd=0;
int rouletteNum=0;

System.out.println("Welcome to the Roulette\n");

for (int roll = 1; roll <=10000; roll++)
{
rouletteNum = generator.nextInt(39); //0-38

if (rouletteNum == 0)
green++;
else if (rouletteNum <= 10)
red++;
else if (rouletteNum <= 18)
black++;
else if (rouletteNum <= 28)
even++;
else odd++;
}

System.out.println ("Green =" + green);
System.out.println ("Red =" + red);
System.out.println ("Black =" + black);
System.out.println ("Odd =" + odd);
System.out.println ("Even =" + even);
}
}
Last edited by jcharhyde; 10-29-2012 at 01:44 AM.

2. ## Re: Roulette Wheel Quick Help

Simple way to see if a number is odd or even is to mod it by 2. If the result is 0 then it is even. Do that and you only have to work out if it is black or red.

3. Member
Join Date
Oct 2012
Posts
5
Rep Power
0

## Re: Roulette Wheel Quick Help

ahh sorry for my ignorance but what do you mean mod it by two? divide the number you mean? sorry thanks for the reply man

4. Member
Join Date
Oct 2012
Posts
5
Rep Power
0

## Re: Roulette Wheel Quick Help

also had one more question, this is part of my code:

else if (num==1||num==3||num==5||num==7||num==9||num==19|| num==21||num==23||num==25||num==27)
red++;

is there any way to red++ and odds++ in that same statement? i can one or the other to increase but not at the same time?

5. ## Re: Roulette Wheel Quick Help

1. You didn't bother to reply to the two responses on your first thread http://www.java-forums.org/new-java/...cendingly.html . Not the best way to continue to get free help on a forum, that.

2. Please go through http://www.java-forums.org/forum-gui...w-members.html and BB Code List - Java Programming Forum and edit your posts accordingly.

db

6. Member
Join Date
Oct 2012
Posts
5
Rep Power
0

## Re: Roulette Wheel Quick Help

My apologies to all for the bad form. I did read over the guide for new members when I registered. I find this site and forum resourceful even though I rarely make posts myself. I'll reread the guidelines and ensure I don't make the same mistakes in the future. Thank you and again, sorry for the trouble.

7. ## Re: Roulette Wheel Quick Help

Originally Posted by jcharhyde
ahh sorry for my ignorance but what do you mean mod it by two?
Do you have a Java text book?
Does it have an index?
What do you think will happen if you typed "java mod" into google?

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•