BlackBerry Interview Question: How would you draw an "X" on ... | Glassdoor

Interview Question

Software Engineer Interview Ottawa, ON (Canada)

How would you draw an "X" on a screen made from smaller

  "x"s?
Answer

Interview Answer

1 Answer

1

generally, use a loop:

char[][] Xs = new char[MAX_ROW][MAX_COL];

for(int row = 0; row < MAX_COL / 2; row++) {
          Xs[row][row] = 'x' ;
          Xs[row][MAX_COL - row] = 'x' ;
}

Xs[MAX_COL / 2][MAX_COL / 2] = 'x' ;

for(int row = MAX_COL / 2 + 1; row < MAX_COL; row++) {
          Xs[row][row] = 'x' ;
          Xs[row][MAX_COL - row] = 'x' ;
}

draw(Xs);

Anonymous on Feb 1, 2011

Add Answers or Comments

To comment on this, Sign In or Sign Up.