*
The moose likes Java in General and the fly likes Comparing chars at positions in an array Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Comparing chars at positions in an array" Watch "Comparing chars at positions in an array" New topic
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: 18509
    
  40

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: 2367
Did you mean for the second == to be =?
Shaggy Rogers
Greenhorn

Joined: Mar 10, 2006
Posts: 26
>_<
THanks.
 
Consider Paul's rocket mass heater.
 
subject: Comparing chars at positions in an array
 
Similar Threads
Reading characters from a file into an array
July Newsletter Puzzle (Maze Solver)
Trying to fill a 2D array from a file
Filling an Array.
Large blocks of white space while outputting to a file?