• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

Java Programming Help... Again

Krueger81

Diamond Member
I am supposed to be able to throw the dice and then whenever it hits 7 I should add one to the counter. After I hit 100 7s I need to take that amount and find out the odds and display those?

ANy ideas. this is what I have so far. I am stuck where I can't take the amount of throws and count them.. Thanks

Phil

import java.util.*;

public class number_one
{
public static void main(String[] args)
{
int counter = 0, toss = 0, tossseven = 0, odds = 0, randomdice = 6;

while (counter > 100)
{
randomdice = (int)(Math.random() * 6 + 1);
counter++;
}

odds = toss / tossseven;

System.out.println (randomdice);
System.out.println (counter);

}
}
 
Test your randomdice each time it's generated. If it's even, increment tosseven. You should also only be incrementing your counter if randomdice == 7.
 
Originally posted by: kamper
Test your randomdice each time it's generated. If it's even, increment tosseven. You should also only be incrementing your counter if randomdice == 7.

how do I test it

I have added

if (randomdice ==7)
counter++;
 
hmm, dude your while loop is wrong, needs to be < 100. Also you need to add 1 to counter only if randomDice is 7 (if I understand your instructions properly). Lastly, you need to increment too as well.

And as much as I hate saying this, but seriously, do your own homework.
 
Originally posted by: Argo
hmm, dude your while loop is wrong, needs to be < 100. Also you need to add 1 to counter only if randomDice is 7 (if I understand your instructions properly). Lastly, you need to increment too as well.

And as much as I hate saying this, but seriously, do your own homework.

thanks for the help on the < anyway we haven't covered this stuff yet and I am trying to get it done for tommorrow.
 
Back
Top