You are not logged in.

#1 2009-02-05 07:01:27

Cheikh
Member
Registered: 2005-02-07
Posts: 25

Search and replace in two-dimensional array

I need helping searching and replacing trought a two-dimensional array
basically I have:
String array [][] = {"1", "A", "B", "C", },
                  {"2", "A", "B", "C", },
                  {"3", "A", "B", "C", },
                  {"4", "A", "B", "C", },
                   {"5", "A", "B", "C",} };
Ask the user to input two character that are in the array
if the user input (e.g., "1A") I print again the array but replacing A with '*' or until the user quit. Prfer using loop because the array is big

thanks

Offline

#2 2009-02-05 12:43:41

Cerebral
Forum Fellow
From: Waterloo, ON, CA
Registered: 2005-04-08
Posts: 3,108
Website

Re: Search and replace in two-dimensional array

I suggest a "two-nested-loops" approach if you want to brute-force this (which you may have to if your array is assumed to be filled with "random" data).  I'm going to avoid going into detailed code examples because this sounds suspiciously like homework, but I'll lay down some pseudocode:

for i in 1 --> max_x
    for j in 1 --> max_y
        check array[i][j], replace if necessary

Offline

Board footer

Powered by FluxBB