• 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

2d Boolean Array  RSS feed

 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Fisrt of all forgive my ignorance, I'm only 5 weeks in on the language.
Im working on a 2d Boolean array that is represented as an imaginary floor, when moving my "rat" across the floor(also the name of the array), I need to be able to leave a trail if it is toggled by the user. almost all of the coding is done but I do not know how to return a Boolean value into a "floor space" as I travel across it can someone just give me a general idea of how to place a boolean value of true onto a 2d array that is already default as false? please do not give me the complete answer, just a gental kick in the right direction.
thanx
 
Ranch Hand
Posts: 5093
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
array[x][y] = true; usually does the trick.
 
Ranch Hand
Posts: 805
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, Daniel -

If I understand what you're looking for, a simple assignment should do the trick. Because you capitalize Boolean, I'm assuming you are using Boolean objects, not primitive data types. You can't modify a Boolean object because the fields are final and there are no setter methods anyway. If you have an array of rows and objects, then you could create a new Boolean with the desired value and assign it to the array element you need to change.

Hope that helps...
 
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It would probably be easier to use the boolean primitive rather than the Boolean wrapper class. In such a case, an assignment will do the job of toggling the value.

Layne
 
Jeff Bosch
Ranch Hand
Posts: 805
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Very true, but if the professor wanted an array of Boolean objects and the student uses an array of boolean primitives, guess what the grade will be!
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!