Fixing Print Square Error in Box Program

  • Thread starter courtrigrad
  • Start date
  • Tags
    Change
In summary, the conversation is about a program that is supposed to print out a square, but is not working properly due to issues with spacing. There is a code provided for a Box class that should work, but the person is asking for help on how to invoke it and view the results. They also mention that if the output is displayed in a non-fixed width font, the spacing may appear incorrect even when it is correct.
  • #1
courtrigrad
1,236
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
  • #2
It should work. (In fact, it DOES work.) How are you invoking it?
 
  • #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.
 

FAQ: Fixing Print Square Error in Box Program

What is the purpose of fixing print square error in box program?

The purpose of fixing print square error in box program is to ensure that the program is accurately calculating and printing the square of a given number without any errors.

What causes print square error in box program?

Print square error in box program can be caused by various factors such as incorrect code syntax, logical errors in the code, or incorrect input values.

How can I fix print square error in box program?

To fix print square error in box program, you can start by carefully reviewing the code and identifying any syntax or logical errors. You can also use debugging tools to track down the source of the error. Additionally, double-checking the input values can also help resolve the error.

Can print square error in box program be prevented?

Yes, print square error in box program can be prevented by following good coding practices, such as writing clean and organized code, testing the program with different input values, and using debugging tools to catch and fix errors early on.

Why is it important to fix print square error in box program?

Fixing print square error in box program is important because it ensures the accuracy and reliability of the program. Errors in the code can result in incorrect calculations and can lead to bigger issues down the line. Fixing the error also improves the overall functionality and user experience of the program.

Similar threads

Replies
7
Views
2K
Replies
2
Views
2K
Replies
2
Views
3K
Replies
3
Views
1K
Replies
1
Views
1K
Back
Top