I'd like someone to suggest a better way to create this pattern in Java which I'm sure is possible:
*********
* *
* *
* *
* *
* *
* *
* *
*********
I'm working my way through a new Java book and am examining string patterns.
public static void drawRectangle() {
// y axis
for( int y = 0; y <= 8; y++ )
{
if( y == 0 || y == 8 )
{
System.out.print( "*********\n" );
if( y == 8 )
{
// Leave loop
break;
}
}
// x axis
for( int x = 0; x <= 8; x++ )
{
if( x == 0 || x == 8 )
{
System.out.print( "*" );
if( x == 8 )
{
System.out.println();
}
}
else
{
System.out.print( " " );
}
}
}
}
Off the top of my head, I'd say that I could replace the values in the loops with constants to work towards. For example:
final static int END_POINT = 8;
Any thoughts?
StringBuilder
. This is for performance reasons, so it is actually not very important for your problem. \$\endgroup\$