A better way to make Making a rectangular-shaped pattern
EDIT
I took your answer into consideration and have adopted your code into a while
loop. I like the fact that the for
loops were placed into their own methods and have subsequent parameters.
Nice improvement I think:
int numAst = 9;
int tracker = 0;
while( tracker < numAst )
{
if( tracker == 0 || tracker == numAst-1 )
{
drawHorizontal(numAst);
if( tracker == numAst-1 )
{
break;
}
}
drawEnds(numAst);
tracker++;
}
A better way to make a rectangular-shaped pattern
EDIT
I took your answer into consideration and have adopted your code into a while
loop. I like the fact that the for
loops were placed into their own methods and have subsequent parameters.
Nice improvement I think:
int numAst = 9;
int tracker = 0;
while( tracker < numAst )
{
if( tracker == 0 || tracker == numAst-1 )
{
drawHorizontal(numAst);
if( tracker == numAst-1 )
{
break;
}
}
drawEnds(numAst);
tracker++;
}
Making a rectangular-shaped pattern
A better way to make this pattern a rectangular- Javashaped pattern
I'd like someone to suggest a better way to create this pattern in javaJava which I'm sure is possible:
I'm working my way through a new Java book and am examining string patterns; here's my code -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:
EDITEDIT
I took your answer into consideration and have adopted your code into a while
loop - I. I like the fact that the for
loops were placed into their own methods and have subsequent parameters.
int numAst = 9;
int tracker = 0;
while( tracker < numAst )
{
if( tracker == 0 || tracker == numAst-1 )
{
drawHorizontal(numAst);
if( tracker == numAst-1 )
{
break;
}
}
drawEnds(numAst);
tracker++;
}
A better way to make this pattern - Java
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; here's my code -
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:
EDIT
I took your answer into consideration and have adopted your code into a while
loop - I like the fact that the for
loops were placed into their own methods and have subsequent parameters.
int numAst = 9;
int tracker = 0;
while( tracker < numAst )
{
if( tracker == 0 || tracker == numAst-1 )
{
drawHorizontal(numAst);
if( tracker == numAst-1 )
{
break;
}
}
drawEnds(numAst);
tracker++;
}
A better way to make a rectangular-shaped pattern
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:
EDIT
I took your answer into consideration and have adopted your code into a while
loop. I like the fact that the for
loops were placed into their own methods and have subsequent parameters.
int numAst = 9;
int tracker = 0;
while( tracker < numAst )
{
if( tracker == 0 || tracker == numAst-1 )
{
drawHorizontal(numAst);
if( tracker == numAst-1 )
{
break;
}
}
drawEnds(numAst);
tracker++;
}