This week's book giveaway is in the OCAJP forum.
We're giving away four copies of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) and have Khalid A Mughal & Rolf W Rasmussen on-line!
See this thread for details.
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

Really long post about multidemensional arrays

 
Alex Ba
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


If you enter 2 candidates and 3 voters, instead of entering votes 3 times, you enter them 6 and I can't see why. Also, for the printVotes method, it just prints 0s. Anyone see any huge holes in my logic? I can't figure out for the life of me why it's not working.
 
Alex Ba
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I should add the main class:

 
Patricia Samuel
Ranch Hand
Posts: 300
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Alex,

Please let me know what input this line takes for the test case you have provided -
# System.out.println("\nPlease enter your vote");
# System.out.println("Please enter votes: 1,2,3,4,5 etc");
# Scanner kb = new Scanner(System.in);


Thanks
Patricia
 
Campbell Ritchie
Sheriff
Pie
Posts: 49733
69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That wasn't a long post.

What's a multidimensional array? Java doesn't support them. It supports arrays of arrays.

And for your logic, you will have to get a pencil and paper and go through the control flow in your program until you find why you are asking six times. Hint 3 × 2 = 6
 
Alex Ba
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Patricia Samuel wrote:Hi Alex,

Please let me know what input this line takes for the test case you have provided -
# System.out.println("\nPlease enter your vote");
# System.out.println("Please enter votes: 1,2,3,4,5 etc");
# Scanner kb = new Scanner(System.in);


Thanks
Patricia


That input is in the while loop


The input would be something like 1,2 or 2,1 aka, which person is your number 1 preference, and which is your number 2. From there, that string is getting split up into individual characters and entered into various slots in the array. It's not doing that.
 
Alex Ba
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey I figured it out.
is the current while loop. It seems to be working.
 
Patricia Samuel
Ranch Hand
Posts: 300
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Great

I was just going to get my pencil and paper
 
Alex Ba
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Seems as though doing things on paper first makes programming easier.
Wish my professor would've mentioned that
 
Campbell Ritchie
Sheriff
Pie
Posts: 49733
69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I only go to one module now, and sit at the back and help the undergraduates. I seem to spend half my time telling them to get a small pencil . . .






























. . . and a large eraser
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic