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 Help with program

Before you post, read our: Rules & Posting Guidelines

Enjoy an ad free experience by logging in. Not a member yet? Register.
 12-15-2008, 07:57 PM PM User | #1 porknbeans New Coder   Join Date: Dec 2008 Posts: 14 Thanks: 4 Thanked 0 Times in 0 Posts Help with program i am writing a program for my java class due tomorrow and im stuck. im trying to have my program generate 100 random numbers between 0 and 9 and then count how many time each number was generated. for example. 2 6 3 6 8 4 2 4 9 5 0-0 1-0 2-2 3-1 4-1 5-1 6-2 7-0 8-1 9-1 Code: int[] count= new int[9]; int x; int y; for(y=0;y<=99;++y) { int num=(int)(Math.random() * 10); for(x=0;x<=9;++x) { if(num==x) count[x]=count[x]+1; } } for(x=0;x<=9;++x) System.out.println(count[x]);
 12-16-2008, 07:27 AM PM User | #2 shyam Senior Coder     Join Date: Jul 2005 Posts: 1,563 Thanks: 2 Thanked 163 Times in 160 Posts where are u stuck? __________________ You never have to change anything you got up in the middle of the night to write. -- Saul Bellow
 12-16-2008, 12:59 PM PM User | #3 Roelf Senior Coder   Join Date: Jun 2002 Location: Zwolle, The Netherlands Posts: 1,120 Thanks: 2 Thanked 31 Times in 31 Posts only thing i had to change to make it work was the array to hold the count: int[] count= new int[10]; you need an array to hold 10 positions, not 9 __________________ I am the luckiest man in the world
 Users who have thanked Roelf for this post: porknbeans (12-18-2008)

 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 10:49 AM.