The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.

Re: Java Programming Exercise

...
Here's my code:
...
For some reason, the program keeps saying that it took 1 time to generate snake eyes.

If it says that every time, then there are a couple of possibilities:

Either it is not counting correctly, or it is not looping correctly, or the logic that gets the dice values is incorrect. (Note that more than thing might be incorrect.)

Question: How can we know where the bad behavior comes from?

Answer: Make the program tell us.

Put some print statements to show exactly what the program is working on. (I reformatted the spacing and indentation slightly, but the important point is the print statements that show the flow and the values.)

Re: Java Programming Exercise

Originally Posted by Fubarable

..enclose all blocks in curly braces, even one line blocks...

Sound advice. It was already on my list of "Forty-two Suggestions for Java Programmers' Peace Of Mind." (Also made the C list and the C++ list.) I always do this, and I recommend that others do it also.

However, I do have a problem with the following:

Originally Posted by Fubarable

Doing this will solve your problem.

Well, here's the thing:

When you make an assertion like this and people follow the suggestion and find that it does not solve the problem, they might get discouraged.

I wouldn't want that to happen, and I am pretty sure that you wouldn't either. I mean, did you actually test anything in the Original Poster's program related to your suggestion?

Namely...

Originally Posted by Garron5899

program keeps saying that it took 1 time to generate snake eyes

Here's my assertion, borne out by my testing (aided by the use of print suggestions from my previous post):
The fundamental problem reported by the Original Poster has nothing to do with whether one or two statements following the "else" are or are not enclosed in braces.