Slight Change

1,233
1
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!
 
1,037
1
It should work. (In fact, it DOES work.) How are you invoking it?
 
299
1
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.
 

Related Threads for: Slight Change

Replies
2
Views
3K

Physics Forums Values

We Value Quality
• Topics based on mainstream science
• Proper English grammar and spelling
We Value Civility
• Positive and compassionate attitudes
• Patience while debating
We Value Productivity
• Disciplined to remain on-topic
• Recognition of own weaknesses
• Solo and co-op problem solving
Top