| Author |
Comparing chars at positions in an array
|
Shaggy Rogers
Greenhorn
Joined: Mar 10, 2006
Posts: 26
|
|
Hello all, I'm coding something like for(int i = 0; i < maze.length; i++) { for(int x = 0; x < maze[0].length; x++) { if(maze[i][x] == ('.')) { maze[i][x] == ('!'); } System.out.print(maze[i][x]); } that finds a '.' char in a 2D array and replaces it with a '!' character. However, using == does not work. I have tried using .equals as well and get a dereferencing error. Any help on how to compare the characters would be greatly appreciated, thanks.
|
 |
Henry Wong
author
Sheriff
Joined: Sep 28, 2004
Posts: 16815
|
|
This is nothing wrong with the comparison. It is the assignment that is incorrect. Don't you mean this... The "==" is not a valid assignment operator. Henry
|
Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
|
 |
Keith Lynn
Ranch Hand
Joined: Feb 07, 2005
Posts: 2341
|
|
|
Did you mean for the second == to be =?
|
 |
Shaggy Rogers
Greenhorn
Joined: Mar 10, 2006
Posts: 26
|
|
>_< THanks.
|
 |
 |
|
|
subject: Comparing chars at positions in an array
|
|
|