• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Comparing chars at positions in an array

 
Shaggy Rogers
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Marshal
Pie
Posts: 21493
84
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Keith Lynn
Ranch Hand
Posts: 2409
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you mean for the second == to be =?
 
Shaggy Rogers
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
>_<
THanks.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic