fork(3) download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static void main (String[] args) throws java.lang.Exception
  11. {
  12. int rows=4;
  13. int cols=4;
  14. int [][] gameboard = new int[rows][cols];
  15. int cellSize = 4;
  16. int rowLength = cols * cellSize + cols + 1;
  17. final char[] array = new char[rowLength];
  18. Arrays.fill(array, '-');
  19. String rowDivider = new String(array);
  20. for(int i = 0; i < gameboard.length; i++)
  21. {
  22. System.out.println(rowDivider);
  23. for(int j = 0; j < gameboard[i].length; j++)
  24. {
  25. System.out.printf("|%"+cellSize+"d",gameboard[i][j]);
  26. if(j == (gameboard[i].length - 1)) System.out.println("|");
  27. }
  28. }
  29. System.out.println(rowDivider);
  30. }
  31. }
Success #stdin #stdout 0.07s 380224KB
stdin
Standard input is empty
stdout
-----------
|   0|   0|
-----------
|   0|   0|
-----------
|   0|   0|
-----------