Advertisement
Guest User

Untitled

a guest
Jul 27th, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.57 KB | None | 0 0
  1. /*
  2.  * To change this template, choose Tools | Templates
  3.  * and open the template in the editor.
  4.  */
  5.  
  6. package treedraw;
  7.  
  8. /**
  9.  *
  10.  * @author mute
  11.  */
  12. public class Main {
  13.  
  14.     /**
  15.      * @param args the command line arguments
  16.      */
  17.     public static void main(String[] args) {
  18.                 final int height = 9; //Tree height
  19.         final int stemHeight = 2;
  20.         //counters
  21.         int count = 0;
  22.         int whiteCount = 4;
  23.         int drawCount = 1;
  24.         int i;
  25.  
  26.         //Strings
  27.         String drawSpace = "*";
  28.         String whiteSpace = "    ";
  29.         while ( count <= (height - 2) ) {
  30.  
  31.             while ( whiteCount >= 0 ) {
  32.  
  33.                 for ( i = whiteCount; i >= 0; i-- )  //This loop adjust the whiteSpace ' ' String
  34.                                     whiteSpace = whiteSpace.substring( 1, whiteSpace.length()-1);
  35.  
  36.                 for ( i = drawCount; i >= 0; i--)  //This loop adjusts the drawSpace '*' String
  37.                     drawSpace += '*';
  38.                 System.out.println( whiteSpace + drawSpace + whiteSpace );
  39.                 drawCount++;  //iterates the counters
  40.                 whiteCount--;
  41.                 count++;
  42.  
  43.             }
  44.                 }
  45.  
  46.         while ( count > ( height - 2 ) && count < height ) {
  47.             drawCount = 3;
  48.             whiteCount = 3;
  49.                         whiteSpace = " ";
  50.                         drawSpace = "*";
  51.             //Resused for loop to draw stem rather than just write the characters...could be methodized later
  52.             for ( i = whiteCount; i >= 0; i-- )
  53.                 whiteSpace += ' ';
  54.             for ( i = drawCount; i >= 0; i-- )
  55.                     drawSpace += '*';
  56.             for ( i = stemHeight; i >= 0; i--)
  57.                 System.out.println( whiteSpace + drawSpace + whiteSpace );
  58.         }
  59.     }
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement