How can I print out a simple int [][] in the matrix box format like the format in which we handwrite matrices in. A simple run of loops doesn\'t apparently work. If it helps
public static void main(String[] args)
{
int [] [] ar=
{
{12,33,23},
{34,56,75},
{14,76,89},
{45,87,20}
};
I prefer using enhanced loop in Java
Since our ar is an array of array [2D]. So, when you iterate over it, you will first get an array, and then you can iterate over that array to get individual elements.
for(int[] num: ar)
{
for(int ele : num)
{
System.out.print(" " +ele);
}
System.out.println(" " );
}
}