• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • paul wheaton
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Tim Holloway
  • Carey Brown
  • salvin francis

Really long post about multidemensional arrays

 
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:

 
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
 
Marshal
Posts: 65457
248
  • 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
Marshal
Posts: 65457
248
  • 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
 
I think I'll just lie down here for a second. And ponder this tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!