Okay so the program I was asked to design requires the simulation of rolling three dice and printing out the outcome of each turnout while adding to a counter until all three dice are different numbers. So a sample output would be:
What do you mean by access modifiers? I get what you said about the variable declaration inside the loop. I also still get an error for private Random myDie; and I don't know why.
Last edited by IMtheBESTatJAVA; Nov 20th, 2008 at 9:03 am.
private, public, protected are access modifiers. They only apply to class and instance variables, not local variables declared inside of a method (which myDie is).
Also, in a loop, if you want to use a variable (lets call it var) in the conditional (i.e. in the var != whatever part), that variable cannot be declared inside of the loop (it can be defined there, i.e. getr a new value there), but it can't be declared there.
Last edited by masijade; Nov 20th, 2008 at 9:10 am.
Okay well I tried moving the declarations for dieRollOne, Two, and Three outside of the loop, and no troubles. But now, when I tried moving the access modifiers outside of the method, it says I need an identifier for myDie = new Random (seedInt);.
public class Rolling
{
private Random myDie;
double seed = Math.random() * 10;
myDie = new Random (seedInt);
int seedInt = (int)seed;
int counter = 0;
int dieRollOne;
int dieRollTwo;
int dieRollThree;
public static void main(String[] args)
{
do
{
dieRollOne = die.nextInt(6) + 1;
dieRollTwo = die.nextInt(6) + 1;
dieRollThree = die.nextInt(6) + 1;
counter += 1;
System.out.println(dieRollOne + " " + dieRollTwo + " " + dieRollThree);
}
Im new at java, so using these terms doesn't really help me out too much. I mean, you could possibly couple what you mean with relative code, whether it be for my program or just a sample. Thanks...
Im new at java, so using these terms doesn't really help me out too much. .
since this are the appropriate terms, it does help to mention them. that way, you can learn what they mean/are ..
if you stick to java, you're bound to hear them a lot more
No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.