Friday, 15 February 2013

Local variables, "dead code" and 2D arrays problems in Java -



Local variables, "dead code" and 2D arrays problems in Java -

i'm having few problems while developing next code in java:

setpos(x, y); (int = 0; x < size; i++) { (int j = 0; y < size; j++) { if (board[x][y] == 'k') { system.out.println("you've found key! congrats!"); homecoming true; }

eclipse notice me i , j, local variables, they're not used : the value of local variable not used . if alter i , write x instead, tells me i'm repeating variable.

j++ tagged dead code ?

also, have search concrete type of element on diagonal of bidimensional array, i've been trying 2 loops, above, no result yet.

hope can help me, in advance!

eclipse notice me i , j, local variables, they're not used

that's because you're not using them. you've assigned them values, , you've later incremented (added to) values, you've never used them anything.

j++ tagged "dead code" (?)

for same reason, code increments value of j, j never used, code nothing. "dead code" refers code has no purpose or never run.

your loops don't create lot of sense. instance:

for (int = 0; x < size; i++) {

normally for loop, command variable (i in case) should appear in all three of parts of for statement (the initializer, test, , increment), this:

for (int = 0; < size; i++) { // alter here -^

but you're not doing that, you're using i in initializer , increment, never in test (x < size). same true of loop j.

similarly, unless there's changing value of x, y, and/or size, loops either never run (because x or y >= size), run once (because happens board[x][u] == 'k'), or they'll run forever (because x or y < size , since nil changes that, maintain looping...).

java arrays local

No comments:

Post a Comment