Flash Website Builder- Trendy Site Builder is a Flash Site Building tool that helps users build stunning websites. Check Out Custom Custom Logo Design by LogoBee. Website Design and Free Logo Templates available.
 CodingForums.com For Loops Help
 User Name Remember Me? Password

Before you post, read our: Rules & Posting Guidelines

Enjoy an ad free experience by logging in. Not a member yet? Register.
 08-02-2008, 01:48 AM PM User | #1 cancam New to the CF scene   Join Date: Aug 2008 Posts: 1 Thanks: 0 Thanked 0 Times in 0 Posts For Loops Help At the moment I am learning Java, and I am currently going through pretty much basics. I have an assignment that makes me practice for loops and random numbers. The assignment tells to write a program to simulate tossing a pair of 11-sided dice and determine the percentage of times each possible combination of the dice is rolled. I'm supposed to ask the user how many times to roll the dice, and from there calculate the probability of the sum to come up. For now, I'm doing it with a 4 sided dice. What I'm having a problem with is making the loops calculate the probability for the sums. This is what I have: Code: ``` int rolls; int counter = 0; int dice1 = 0; int dice2 = 0; Scanner in = new Scanner(System.in); System.out.print("Number of rolls: "); rolls = in.nextInt(); Random randNumList = new Random(); timesRolled = 0; System.out.println(); System.out.println("Times rolled: " + timesRolled); System.out.println("Sum of dice Probability"); for(timesRolled = 0; rolls > timesRolled; timesRolled++) { dice1 = randNumList.nextInt(5); dice2 = randNumList.nextInt(5); for(int diceSum = (dice1 + dice2); diceSum == 2; counter++) { double prob = (double)counter / 8; System.out.println(" 2s: " + prob); } for(int diceSum = dice1 + dice2; diceSum == 3; counter++) { double prob = (double)counter / 8; System.out.println(" 3s: " + prob); } for(int diceSum = dice1 + dice2; diceSum == 4; counter++) { double prob = (double)counter / 8; System.out.println(" 4s: " + prob); } for(int diceSum = dice1 + dice2; diceSum == 5; counter++) { double prob = (double)counter / 8; System.out.println(" 5s: " + prob); } for(int diceSum = dice1 + dice2; diceSum == 6; counter++) { double prob = (double)counter / 8; System.out.println(" 6s: " + prob); } for(int diceSum = dice1 + dice2; diceSum == 7; counter++) { double prob = (double)counter / 8; System.out.println(" 7s: " + prob); } for(int diceSum = dice1 + dice2; diceSum == 8; counter++) { double prob = (double)counter / 8; System.out.println(" 8s: " + prob); } }``` As you can see, it's very basic printing-to-terminal kind of stuff. When I run this, it doesn't work properly. Any help is appreciated. I've asked my teacher for help but all he does is give me hints, and its frustrating because I'm good with methods, but not with the math part. Thanks
 08-20-2008, 02:46 PM PM User | #2 Celtboy Regular Coder   Join Date: May 2002 Location: Virginia, USA Posts: 620 Thanks: 0 Thanked 6 Times in 6 Posts I'm confused. Are you supposed to determine the probability of sums of the die or the percentage of sums actually rolled?

 Bookmarks

 Thread Tools Rate This Thread Rate This Thread: 5 : Excellent 4 : Good 3 : Average 2 : Bad 1 : Terrible

 Posting Rules You may not post new threads You may not post replies You may not post attachments You may not edit your posts BB code is On Smilies are On [IMG] code is On HTML code is Off Forum Rules
 Forum Jump User Control Panel Private Messages Subscriptions Who's Online Search Forums Forums Home :: Client side development     JavaScript programming         DOM and JSON scripting         Ajax and Design         JavaScript frameworks         Post a JavaScript     HTML & CSS     XML     Flash & ActionScript         Adobe Flex     Graphics and Multimedia discussions     General web building         Site reviews         Building for mobile devices :: Server side development     Apache configuration     Perl/ CGI     PHP         Post a PHP snippet     MySQL         Other Databases     Ruby & Ruby On Rails     ASP     ASP.NET     Java and JSP     Other server side languages/ issues         ColdFusion         Python :: Computing & Sciences     Computer Programming     Computer/PC discussions     Geek News and Humour Web Projects and Services Marketplace     Web Projects         Small projects (quick fixes and changes)         Medium projects (new script, new features, etc)         Large Projects (new web application, complex features etc)         Unknown sized projects (request quote)         Vacant job positions         Looking for work/ for hire         Project collaboration/ partnership         Paid work offers and requests (Now CLOSED)     Career, job, and business ideas or advice     Domains, Sites, and Designs for sale         Domains for sale         Websites for sale         Design templates and graphics for sale :: Other forums     Member Offers     Forum feedback and announcements

All times are GMT +1. The time now is 01:39 AM.