I have a code snippet (see snippet below) that generates an array like this: [0, 3, 1, -2, 0, -1, 1, 1, -2]. The int numbers here represent movements from one position to another. I would like to have the numerical values translated into text that would represent directions starting from the 0. A Positive number represents the number of steps to the East--so the number 3 would be translated into "eee", the number two would be "ee" and so on. Negative values represents steps in the opposite direct West so that -2 would be displayed as ww
, and so on. No movement should be represented as 0.
I'm pretty new to all this and am not sure how the take the values from the array and turn them into the instructions as described above.
The code below shows how the array of integers is generated--subtracting the next location from the previous to get the number of steps between them.
int [] differenceX = new int [noOfRecordsX];
differenceX [0] = 0;
for( int i=0; i < noOfRecordsX -1 ;i++)
{
differenceX [i+1]= inputX [i+1] - inputX[i];
}
From here I want to generate the text describing the steps in the respective direction so that this array:
[0, 3, 1, -2, 0, -1, 1, 1, -2]
would be transformed to this string:
0,eee,e,ww,0,w,e,e,ww