Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

help with arrays

 
M Mangion
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

I have an array which stores info about 20 teams. I created another array which stores the exact info of the first array but the teams are shuffled. I also have a third array this time of 10 which is being used to store matches i.e. 10 matches between the 20 teams.

Now for the matches, I have a class which has the following constructor:



Now for the left and right team I want to pass the [0] and [1] from the shuffled array for match 1, [2] and [3] for match 2 etc.

So to populate the Match array I am trying to use the following code:



However, the system.out statement is not being displayed in the console. Any ideas what I am doing wrong?
 
fred rosenberger
lowercase baba
Bartender
Posts: 12184
34
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
when all else fails, pepper your code with more println statements. I have been known to put "entering method X" and "leaving method X" in every single method in my code to make sure methods I think are being called really are.

Once you are SURE that method is called, put on as the first thing in your loop: "entering the loop now!"

print your conditions, print when you increment your counters, etc.
 
John Jai
Rancher
Posts: 1776
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And check if size of mt is not 10. I see you are saying you have an array of size 10 to hold the matches. Then below will give exception when i in for is going beyond 10.
 
M Mangion
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank you for your replies. Regarding the loop going beyond 10, you were right and i changed it as follows:



However, this function is still not running at all, i am not even getting the "Started" print statement. The function the it is being called before it from the main is the following, which is the last thing that it is being run successfully(since the array is being shuffled).



the ft mentioned above is the original array before the teams are being shuffled.

Thank you for any feedback.
 
M Mangion
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
the problem seems to be coming from the shuffleTeams method because on line 19 in the above code, I added a simply system.out statement to display that the loop has ended, however not even this print statement is being shown in the console. Therefore the console is just showing the 20 teams shuffled and the program is ending their.

Any feedback would be greatly appreciated, as I cannot understand what I am doing wrong.

Thanks in advance for your help.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic