| Author |
Really long post about multidemensional arrays
|
Alex Ba
Ranch Hand
Joined: Oct 14, 2009
Posts: 35
|
|
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
Joined: Oct 14, 2009
Posts: 35
|
|
I should add the main class:
|
 |
Patricia Samuel
Ranch Hand
Joined: Sep 12, 2007
Posts: 300
|
|
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
Joined: Oct 13, 2005
Posts: 32689
|
|
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
Joined: Oct 14, 2009
Posts: 35
|
|
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
Joined: Oct 14, 2009
Posts: 35
|
|
Hey I figured it out.
is the current while loop. It seems to be working.
|
 |
Patricia Samuel
Ranch Hand
Joined: Sep 12, 2007
Posts: 300
|
|
Great
I was just going to get my pencil and paper
|
 |
Alex Ba
Ranch Hand
Joined: Oct 14, 2009
Posts: 35
|
|
Seems as though doing things on paper first makes programming easier.
Wish my professor would've mentioned that
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32689
|
|
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
|
 |
 |
|
|
subject: Really long post about multidemensional arrays
|
|
|