• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

2d Boolean Array

 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
array[x][y] = true; usually does the trick.
 
Ranch Hand
Posts: 808
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 808
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
Don't sweat petty things, or pet sweaty things. But cuddle this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic