Hi everyone, this is my first post on this forum. I'm having trouble with a program assigned for homework. I would say that I am at a beginners level in java. Here's my code in class Bug:
String[][] pathInfo = new String[5][25];
........;
........;
/*
Prints array for testing/debug use
@return pathInfo 2D array
*/
public void printArray(String[][] pathInfo)
{
for (int row = 0; row < 5; row++)
{
for (int column = 0; column < 25; column++)
{
if (pathInfo[row][column] == "*") !!!!<<<<------I think the problem lies here
{
System.out.print(pathInfo[row][column]);
}
else
{}
}
}
}
public String[][] fillArrays(String[][] pathInfo) throws FileNotFoundException
{
Scanner bugPathScan = new Scanner(new File("bugpath.txt"));
bugPathScan.useDelimiter("");
for (int row = 0; row < pathInfo.length; row++)
{
for (int column = 0; column < pathInfo[row].length; column++)
{
pathInfo[row][column] = bugPathScan.next();
}
}
return pathInfo;
}
It fills the array with info from a txt file. The text file contains a bunch of symbols, and looks something like this:
****-*--*
*-----****
*-----*--* <--my goal is to print only the '*' characters and skip the '-'
****-*--*
How could I compare the value at the current position within the array to the "*" character? I've tried changing the array type to char[][] but I can't use the scanner to read in a char value. Any ideas? Your help is greatly appreciated