This week's book giveaway is in the Cloud/Virtualization forum.
We're giving away four copies of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds and have James Denton on-line!
See this thread for details.
Win a copy of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds this week in the Cloud/Virtualization forum!
  • 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:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

Multidimensional arrays  RSS feed

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys, Im here for some help. I have assignment that Im working on where I have to read in a file that looks like this:


I have to make an array that is [rows]x[leftSeats + rightSeats],
then split the remaining info by split("-") and assign the seats.
Here is what I have so far:


I am reading in the rows and left and right seat and turning them into integers, however, using the if statements, I cant make the array[][].
Any suggestions?
Thanks a lot
 
Marshal
Posts: 60098
188
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to JavaRanch

If I had that (it is quite awkward for a beginners' assignment) I would put the names and numbers of seats into a Map, using <String, Integer> as its types, so you get

rows |-> 7
leftSeats |-> 1
rightSeats |-> 2

Then you can do arithmetic on the different numbers and get a something[7][3] array. By the way: There is no such things as a multi-dimensional array in Java, only arrays of arrays.

Test the first character of each String read, and look in the Character class for methods which tell you whether it begins with a row number.

****************************************************************************

Other people are bound to have different ideas.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!