• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Help fixing up my program?

 
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi I have to create a program that plays an elimination game. The user has to input the number of players and the number of "cycles" or how much the program counts by. So for example if I input 8 players and 4 cycles then the first player out will be player 4 and then the next one would be player 8, and then it goes on and on until there is one winner. I thought I finished my program but for some reason it gets the wrong answer half the time. Then to make matters worse my teacher decided to tell us that we can't use array lists and we have to use arrays instead today... So I really need some help changing my code to have an array in it and making it work. Here is my code



 
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why have you got so much code in the main method?
Why are you using option panes for keyboard input rather than a Scanner?
I presume you will have a List whose size is the same as one of the numbers you enter? Why can't you create an array that size?
Please explain how you are eliminating the players. If you are removing things from a LIst, that is much easier than removing things from an array. You would have to move all the following elements one place up and maybe null out the last element. Are you aware of the System#arraycopy() method? There are also copying methods in the Arrays class.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic