java


Find how many of one element is in a 2D array


I am having trouble attempting to find how many integers other than 0 exist in a 2D array. How do I figure this out?
My attempted code:
for (int i = 0; i < game.length; i++) {
for (int j = 0; j < game[i].length; j++) {
if (game[i][j] != 0) {
landOwned++;
}
}
Sadly that did not work, and my logic was horrible there -- just to say -- it was a guess. I tried to what things were not zero. For some reason, this didn't work correctly.
Here is my array (game) code: static int[][] game = new int[10][10];
A simple 10x10 2D int array.
I believe I found the answer:
Since my game automatically generates water in the array (int number 4 (stored into the array)) I had to add an extra if statement inside the game[i][j] != 0 statement. I totally forgot all about that, but thanks for your help.

Related Links

Connecting to mySQL Database with Java
Can I get an instance of a class that implements an interface?
Finding the range of ints in a scanner
why i can interchange field values inside a class using class reference but can't interchange the references themselves
Is it okay to inherit classes in java even if it is not meant for that job
BlackBerry - get error code 411
how to create draggable toggle button in Android
Permutation of a 2 dimensional arraylist
Cast a String object to XMLNode object
how to resolve eclipse error Source not found
Can Mirth send JavaBeans on JMS?
How are Java interfaces used? [closed]
Using a external jar. No suitable driver found for jdbc:sqlserver
Java synchronizing a method in a class
Hibernate : refresh on detached object - weird behavior
Java program Not running in Eclipse [duplicate]

Categories

HOME
variables
gitlab
pycharm
reserved
ip
ebean
fingerprint
django-imagekit
session-variables
offline
u-sql
visual-studio-cordova
dynamics-crm-online
ghc
seaborn
pythonanywhere
excel-vba-mac
introduction
nas
clickonce
php-openssl
claims-based-identity
android-widget
django-storage
wtx
dbclient
kendo-datasource
directx-10
jspresso
hybridauth
azure-sql-database
force-layout
bytecode-manipulation
overlap
swift3.0.2
dynamics-crm-2013
uft-api
broadcastreceiver
grid.mvc
nomethoderror
eigenvalue
spring-security-kerberos
isbn
acoustics
scorm
logfiles
filepicker
pango
dandelion
jlink
orthogonal
specrun
nested-sets
xcb
google-feed-api
android-textview
etsy
mongocsharpdriver
fuzzy-search
qcustomplot
freelancer.com-api
cartesian-product
eclipse-clp
kcachegrind
c++03
npapi
block-device
rdtsc
id3v2
tld
rebol3
web2py-modules
cos
eclipse-memory-analyzer
jquery-mobile-dialog
android-hardware
viewswitcher
onsubmit
nsmanagedobject
reddot
pendrive
mercurial-server
winbugs14
user-friendly
eqatec
3gp
misv

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App