Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- for( lineNumber = 1; lineNumber <= totalSize; lineNumber++ )
- {
- currentLine = "";
- /*
- * space and star keep track of how many trailing spaces or
- * stars are being printed on each line.
- */
- int space, star;
- // If the diamond is even, there won't be a point on the top or
- // bottom, and the longest line will be printed twice.
- if( isEven )
- {
- // The number of leading space is | longestLine - lineNumber |
- for( space = 0; space < Math.abs(longestLine - lineNumber);
- space++ )
- {
- currentLine += " ";
- }
- // The number of *s is the total size minus how many spaces
- // have already been used on either side.
- for( star = 0; star < (-2 * Math.abs(longestLine - lineNumber) + totalSize); star++ )
- {
- currentLine += "*";
- }
- // Repeat the longest line if that's what we're on
- if( lineNumber == longestLine )
- {
- currentLine += "\n" + currentLine;
- }
- }
- // For regular diamonds
- else
- {
- // The number of leading spaces is | longestLine - lineNumber |
- for( space = 0; space < Math.abs(longestLine - lineNumber + 1);
- space++ )
- {
- currentLine += " ";
- }
- // The number of *s is the total size minus how many spaces
- // have already been used on either side.
- for( star = 0; star < (-2 * Math.abs(longestLine - lineNumber + 1) + totalSize);
- star++ )
- {
- currentLine += "*";
- }
- }
- currentLine += "\n";
- diamond += currentLine;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement