'How to separate by lines a 2d array grid in java?

I'm trying to to create a basic mutiplication table printed out as a grid 2d integer array, basicly I'm having trouble to sepatate the numbers with lines for example "----" or |-|, anyway, below is the basic 2d integer array already showing a multiplication table. Please help to separate each number with lines to get view as an excell table or smtg like that.

package Multip;

public class Multitest {

public static void main(String[] args) {

int[][] multiplicationTable = new int[10][10];

    for (int row=0; row<10; row++) {
      for (int col=0; col<10; col++) {
          
    multiplicationTable[row][col] = (row+1) * (col+1);
  }
}

    for (int row = 0; row < multiplicationTable.length; row++) {    
        
for (row = 0; row < multiplicationTable.length; row++) {

    for (int col = 0; col < multiplicationTable[row].length; col++) {       
        
       System.out.printf("%4d", multiplicationTable[row][col]);
  }       
    System.out.println();
}
    }
}

}



Solution 1:[1]

You can print a new line with underscore in another for loop after your initial loop which prints the numbers. Then your inner loop might look something like this. The count of underscore would be the space you're giving in between each digit

for (int col = 0; col < multiplicationTable[row].length; col++) {

    System.out.printf(" %4d |", multiplicationTable[row][col]);
}
System.out.println();
for (int col = 0; col < multiplicationTable[row].length; col++) {

    System.out.print("_______");
}
System.out.println();

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Singh3y