Advertisement
gdog2u

TreeGenFixed

May 11th, 2014
269
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.66 KB | None | 0 0
  1.     public static String printTree(char t, char b, int s){
  2.         String out = "";
  3.         int test = s - s + 1;
  4.         for(int i = 0; i <= s/2; i++){
  5.             for(int k = 0; k < (Math.ceil(s/2)+1)-(i+1); k++){
  6.                 out += " ";
  7.             }
  8.             for(int j = 0; j < test; j++){
  9.                 out += t;
  10.             }
  11.             test+=2;
  12.             out += "\n";
  13.         }
  14.        
  15.         for(int i = 0; i < (test*0.25)-2; i++){
  16.             out+= " ";
  17.         }
  18.         //this is where my error of having it off by 1 for certain numbers. In my previous one, you saw my over-thinking process.
  19.         if((test/2)%2 == 0){
  20.             for(int i = 0; i <= test/2; i++){
  21.                 out+= b;
  22.             }
  23.         }else{
  24.             for(int i = 0; i <= test/2+1; i++){
  25.                 out+= b;
  26.             }
  27.         }
  28.         return out;
  29.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement