// Non-GUI program to display a diamond pattern of stars. // Written 2/2008 by Wayne Pollock, Tampa Florida USA. import static java.lang.Math.abs; class Diamond { static final int WIDTH = 7; // How many stars in middle (fattest) row. static final int CENTER = 5; // Column index for vertical center axis. public static void main ( String [] args ) { final int range = WIDTH / 2; for ( int i = -range; i <= range; ++i ) { int numStars = WIDTH - abs(i*2); drawChar( ' ', CENTER - numStars/2 ); // Draw leading spaces. drawChar( '*', numStars ); // Draw a row of stars. System.out.println(); // Add a newline. } } // Implementation method to display a "run" of some character: private static void drawChar ( char ch, int numToDraw ) { for ( int i = 0; i < numToDraw; ++i ) System.out.print( ch ); // Not println! } }