fork download
  1. import java.util.Arrays;
  2.  
  3. class Main{
  4. public static void main(String[] a){
  5. Main m = new Main();
  6. m.drawMap(19, 19, '+', 'C', 2, 5);
  7. System.out.println();
  8. m.drawMap(10, 10, '.', 'X', 4, 2);
  9. System.out.println();
  10. m.drawMap(5, 5, 'a', 'B', 5, 5);
  11. }
  12.  
  13. /*
  14.   * Prints a block of sizeX by sizeY of the filler character,
  15.   * where the character at position {posX, posY} (1-indexed) is replaced with the replacement character
  16.   *
  17.   * TODO: Validation checks. Currently assumes posX and posY are always within range of the matrix
  18.   */
  19. public void drawMap(int sizeX, int sizeY, char fillerChar, char replacementChar, int posX, int posY){
  20. // Create a char-matrix of dimensions sizeX by sizeY
  21. char[][] matrix = new char[sizeX][sizeY];
  22.  
  23. // Fill this matrix initially with the mapP character
  24. for(char[] row : matrix)
  25. Arrays.fill(row, fillerChar);
  26.  
  27. // Replace the character at position {currX, currY} (1-indexed) with the mapC character
  28. matrix[posX-1][posY-1] = replacementChar;
  29.  
  30. // Print the matrix
  31. prettyPrintMatrix(matrix);
  32. }
  33.  
  34. private void prettyPrintMatrix(char[][] matrix){
  35. for(char[] row : matrix){
  36. for(char ch : row)
  37. System.out.print(ch);
  38. System.out.println();
  39. }
  40. }
  41. }
Success #stdin #stdout 0.1s 2184192KB
stdin
Standard input is empty
stdout
+++++++++++++++++++
++++C++++++++++++++
+++++++++++++++++++
+++++++++++++++++++
+++++++++++++++++++
+++++++++++++++++++
+++++++++++++++++++
+++++++++++++++++++
+++++++++++++++++++
+++++++++++++++++++
+++++++++++++++++++
+++++++++++++++++++
+++++++++++++++++++
+++++++++++++++++++
+++++++++++++++++++
+++++++++++++++++++
+++++++++++++++++++
+++++++++++++++++++
+++++++++++++++++++

..........
..........
..........
.X........
..........
..........
..........
..........
..........
..........

aaaaa
aaaaa
aaaaa
aaaaa
aaaaB