Fixing Print Square Error in Box Program

  • Thread starter Thread starter courtrigrad
  • Start date Start date
  • Tags Tags
    Change
AI Thread Summary
The program is intended to print a square using 'x' characters for the borders and spaces for the interior. The provided code correctly implements the logic for drawing the square. However, the output may appear misaligned if viewed in a non-fixed width font, which can distort the spacing. Ensuring the output is viewed in a fixed-width font will resolve the appearance issues.
courtrigrad
Messages
1,236
Reaction score
2
Hello all

My program is trying to print out a square but it is not working. I figure something is wrong with the spacing.

Code:
 public class Box
{
  public void getBox( int a )
  {
      for( int i = 0; i < a; i++)
      {
          for( int j = 0; j < a; j++)
          {
             if( i == 0 || i == a-1)
              System.out.print("x");
             else
             if( j == 0 || j == a-1)
              System.out.print("x");
             else
              System.out.print( " " );
            }
              System.out.println( " " );
            
        }
    }
}

Any help is greatly appreciated

Thanks!
 
Computer science news on Phys.org
It should work. (In fact, it DOES work.) How are you invoking it?
 
How are you viewing the results? If the output is displayed in a non fixed width font, the spacing will appear wrong, even when correct.
 
Thread 'ChatGPT Examples, Good and Bad'
I've been experimenting with ChatGPT. Some results are good, some very very bad. I think examples can help expose the properties of this AI. Maybe you can post some of your favorite examples and tell us what they reveal about the properties of this AI. (I had problems with copy/paste of text and formatting, so I'm posting my examples as screen shots. That is a promising start. :smile: But then I provided values V=1, R1=1, R2=2, R3=3 and asked for the value of I. At first, it said...
Sorry if 'Profile Badge' is not the correct term. I have an MS 365 subscription and I've noticed on my Word documents the small circle with my initials in it is sometimes different in colour document to document (it's the circle at the top right of the doc, that, when you hover over it it tells you you're signed in; if you click on it you get a bit more info). Last night I had four docs with a red circle, one with blue. When I closed the blue and opened it again it was red. Today I have 3...
Back
Top