Help with Arrays in Java Required

Lucifer666

all the world needs is me
OP
Member
Joined
Apr 22, 2011
Messages
1,626
Trophies
1
Location
The Fourth Dimension
XP
2,160
Country
United Kingdom
Java isn't exactly my favourite programming language, but for this particular task I'm going to need it, though I'm quite the layman.

So suppose I've created an array:
Code:
int Array[][] = new int[3][3]

and throughout my class, members of the array are assigned numbers.
Eventually I reach a point where I'd like to reference them in an "if...then" statement.

The condition for my if statement is "if everything in Array[1][] is equal to x"; however, I've never dealt with calling an entire row of a multidimensional array in Java, so I'm not quite sure how it's done.

With something as simple as a [3][3] array, I've just been using:
Code:
if (Array[1][0], Array[1][1], Array[1][2] = x) {
which is obviously not the most efficient way to do this, and I'd imagine it can be quite problematic on a larger scale.

So, in Java, how would I call all members of an entire row in a multidimensional array for an if statement? Cheers.
 

Daku93

Well-Known Member
Member
Joined
Jul 24, 2008
Messages
286
Trophies
0
Age
30
Location
Düsseldorf, Germany
Website
usrcheat.cwsurf.de
XP
384
Country
Gambia, The
You could do something like
Code:
boolean isEqual = true;
int x = //Value you want to compare to.
for (int i = 0; i < array[1].length; i++) {
     if (array[1][i] != x) {
          isEqual = false;
          break;
     }
}
so isEqual will tell you if all of them are equal to x or not.
 

Site & Scene News

Popular threads in this forum

General chit-chat
Help Users
  • BigOnYa @ BigOnYa:
    Have you jail broke your ps4 yet?
  • K3Nv2 @ K3Nv2:
    I've been on since 9.0
    +1
  • BigOnYa @ BigOnYa:
    Are you gonna do your ps5 if the hack comes? Is there worries of bans, like the ps3
  • K3Nv2 @ K3Nv2:
    Probably not I got cross play friends
    +1
  • K3Nv2 @ K3Nv2:
    By then I'll have some little mini pc anyway
  • ZeroT21 @ ZeroT21:
    only ps5 updated to latest firmware can go on psn, jailbroken ones just don't use psn or they risk getting flagged or banned, altho spouting profanity in online play alredy does that
  • K3Nv2 @ K3Nv2:
    Keep current Gen consoles stock mod last gen imo
  • DinohScene @ DinohScene:
    Anyone dumb enough to get banned for spouting profanity deserves it.
    +1
  • Y @ YuseiFD:
    Then how come you do it and don't get banned ? or is it a question of getting caught doing it ?
  • BakerMan @ BakerMan:
    wtf is the point of banning swearing in games? that's utterly a dumb decision

    the new generation playing MWII won't be as hardened as the previous one playing original MW2
  • Veho @ Veho:
    What's the point of video games? Kids playing video games won't be as hardened as the previous ones getting shoved down a hillside.
    +2
  • BakerMan @ BakerMan:
    exactly my point
  • BakerMan @ BakerMan:
    kids, yall are fucking pussies, grow some asshair before you even dare touch My Friend Peppa Pig or Mario's Early Years
    +1
  • Bunjolio @ Bunjolio:
    ddddddddddddddddddddddd
  • Bunjolio @ Bunjolio:
    my fingie hurt
  • HiradeGirl @ HiradeGirl:
    Why?
  • Bunjolio @ Bunjolio:
    hangnail thing I think
  • BakerMan @ BakerMan:
    ... that's rough buddy
  • Psionic Roshambo @ Psionic Roshambo:
    This parrot is no more it has ceased to be!
  • Bunjolio @ Bunjolio:
    peepee
    AncientBoi @ AncientBoi: :D:)