Advertisement
Guest User

Untitled

a guest
Aug 29th, 2015
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.07 KB | None | 0 0
  1.         for( lineNumber = 1; lineNumber <= totalSize; lineNumber++ )
  2.         {
  3.             currentLine = "";
  4.            
  5.             /*
  6.              * space and star keep track of how many trailing spaces or
  7.              * stars are being printed on each line.
  8.              */
  9.             int space, star;
  10.  
  11.  
  12.             // If the diamond is even, there won't be a point on the top or
  13.             // bottom, and the longest line will be printed twice.
  14.             if( isEven )
  15.             {
  16.  
  17.                 // The number of leading space is | longestLine - lineNumber |
  18.                 for( space = 0; space < Math.abs(longestLine - lineNumber);
  19.                         space++ )
  20.                 {
  21.                     currentLine += " ";
  22.                 }
  23.  
  24.                 // The number of *s is the total size minus how many spaces
  25.                 // have already been used on either side.
  26.                 for( star = 0; star < (-2 * Math.abs(longestLine - lineNumber) + totalSize); star++ )
  27.                 {
  28.                     currentLine += "*";
  29.                 }
  30.  
  31.                 // Repeat the longest line if that's what we're on
  32.                 if( lineNumber == longestLine )
  33.                 {
  34.                     currentLine += "\n" + currentLine;
  35.                 }
  36.             }
  37.  
  38.             // For regular diamonds
  39.             else
  40.             {
  41.                 // The number of leading spaces is | longestLine - lineNumber |
  42.                 for( space = 0; space < Math.abs(longestLine - lineNumber + 1);
  43.                         space++ )
  44.                 {
  45.                     currentLine += " ";
  46.                 }
  47.  
  48.                 // The number of *s is the total size minus how many spaces
  49.                 // have already been used on either side.
  50.                 for( star = 0; star < (-2 * Math.abs(longestLine - lineNumber + 1) + totalSize);
  51.                         star++ )
  52.                 {
  53.                     currentLine += "*";
  54.                 }
  55.             }
  56.  
  57.             currentLine += "\n";
  58.  
  59.             diamond += currentLine;
  60.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement