-1

This is my print square method

public void printSquare()
{
  DecimalFormat newSquare = new DecimalFormat("00");
  for (int row = 0; row < square.length; row++)
  {
     for (int col = 0; col < square[row].length; col++)
     {  
        System.out.print((newSquare.format(square[row][col])) + " ");
     }
  }
System.out.println();
System.out.println();

}

this is what its output looks like

08 01 06 03 05 07 04 09 02

This is what i need it to look like

08 01 06

03 05 07

04 09 02

I've been trying to figure this out for a long time, any help will be appreciated! Thank you!

Kick Buttowski
  • 6,709
  • 13
  • 37
  • 58

2 Answers2

1

You have to add line break after each row

public void printSquare()
{
  DecimalFormat newSquare = new DecimalFormat("00");
  for (int row = 0; row < square.length; row++)
  {
     for (int col = 0; col < square[row].length; col++)
     {  
        System.out.print((newSquare.format(square[row][col])) + " ");
     }
     System.out.println(); // this will print new line after each row
  }
}
Marcin Szymczak
  • 11,199
  • 5
  • 55
  • 63
1

It would be fixed by using a System.out.println("\n") at the end of the outer loop

public void printSquare()
{
  DecimalFormat newSquare = new DecimalFormat("00");
  for (int row = 0; row < square.length; row++)
  {
     for (int col = 0; col < square[row].length; col++)
     {  
        System.out.print((newSquare.format(square[row][col])) + " ");
     }
     System.out.println("\n");
  }
System.out.println();
System.out.println();
}
Jhon
  • 582
  • 7
  • 28