Skip to main content
Code Review

Return to Question

edited tags
Link
200_success
  • 145.5k
  • 22
  • 190
  • 479
Question Unprotected by rolfl
deleted 580 characters in body; edited tags; edited title
Source Link
Jamal
  • 35.2k
  • 13
  • 134
  • 238

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

Question Protected by Community Bot
added 335 characters in body; edited tags; edited title
Source Link
Jamal
  • 35.2k
  • 13
  • 134
  • 238

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++;
}
show appreciation by up votes and Accepting an answer. spelling
Source Link
Loading
Tweeted twitter.com/#!/StackCodeReview/status/379760737885102080
added edited code
Source Link
Katana24
  • 327
  • 1
  • 3
  • 11
Loading
Source Link
Katana24
  • 327
  • 1
  • 3
  • 11
Loading
lang-java

AltStyle によって変換されたページ (->オリジナル) /