|
-
Help with this loop/program!!!
Hello all, this site was suggested to me by a fellow student and I am hoping to get some help. Have just begun an introduction to Java course and am finding it quite difficult.
In this program I have to roll a dice twice, add up the numbers and report when two ones come up (Snakeyes) and how many rolls it took. I am having trouble with which loop to use and how to count the number of rolls that have been executed before "snakeyes comes up".
Here is what I have done:class SnakeEyes
{
public static void main(String[] args)
{
public static int roll()
{
int total = 0;
int dice1 = (int)(Math.random()*6)+1;
int dice2 = (int)(Math.random()*6)+1;
total = dice1 + dice2;
return total;
}
do
{
for( int count == 0; count++);
roll;
if (total==2) break;
count++;
}
while (total != 2);
System.out.println("You have rolled Snake Eyes!");
System.out.println("This took" +count "rolls");
}
}
If anyone has any suggestions, that would be great! Thankyou.
Steve.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks