Hey guys im working on an ulam's spiral problem and I want to search through the 2D array I have created and find the number entered by the user (numb). I don't get why the if statement (marked with a comment) is always returning false
Edit: Here is the partial code, I have run my genUlam function through the debugger and it DOES in fact return the number, unfortunately this is an assignment so i cannot post the entire code.
public static void main(String[] args)
{
//create scanner object
Scanner input = new Scanner(System.in);
//get input for dimensions
//System.out.print("Enter dimension: ");
int dimension = 3;
//check if dimensions are odd
if (isOdd(dimension) == false)
{
//if input for dimensions is even, get the next odd dimension
dimension += 1;
}
//get input for number in center
// System.out.println("Enter number in spiral: ");
int numb = 2;
//check that number in center is in range of 1 to dim^2
if (numb > Math.pow(dimension,2) && numb < 1)
{
System.out.println("Number not in range");
System.exit(0);
}
//create 2D array using my function
String[][] ulam = {{"1", "2", "3"},{"4","5","6"},{"7","8","9"}};
//check to see if the number user entered does exist, then print array
for(int r = 0; r < dimension - 1; r++)
{
for(int c = 0; c < dimension - 1; c++)
{
//String current = ulam[r][c];
/*the line below should be returning true when match is found, but it is returning false no matter what*/
if(ulam[r][c].equals(Integer.toString(numb)))
{
printArray(ulam, r, dimension);
}
else
{
System.out.println("match not found");
}
}
}
}
public static void printArray(String[][] array, int row, int dimension)
{
for (int i = 0; i < dimension - 1; i++)
{
System.out.println(array[row][i] + " ");
}
}
}