Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Slight Change

  1. Jan 4, 2005 #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 (Text):
     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!
     
  2. jcsd
  3. Jan 4, 2005 #2
    It should work. (In fact, it DOES work.) How are you invoking it?
     
  4. Jan 5, 2005 #3
    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.
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?



Similar Discussions: Slight Change
Loading...