Advertisement
tchenkov

L06u07_ChristmasTree

Feb 16th, 2017
535
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.96 KB | None | 0 0
  1. package Uprajneniq;
  2.  
  3. import java.text.MessageFormat;
  4. import java.util.Scanner;
  5.  
  6. /**
  7.  * Created by todor on 15.02.2017 г..
  8.  */
  9. public class u07_ChristmasTree {
  10.     public static void main(String[] args) {
  11.         Scanner scan = new Scanner(System.in);
  12.         int treeHeight = Integer.parseInt(scan.nextLine());
  13.         String treeLog = " | ";
  14.         String treeBranches = "*";
  15.    
  16.         for (int i = 0; i <= treeHeight; i++) {
  17.             String currentBranch = stringRepeater(treeBranches, i);
  18.             String spaces = stringRepeater(" ", treeHeight - i);
  19.             System.out.println(MessageFormat.format("{0}{1}{2}{1}", spaces, currentBranch, treeLog));
  20.         }
  21.        
  22.     }
  23.    
  24.     static String stringRepeater (String stringToRepeat, int stringRepeatCount){
  25.         String outputString = "";
  26.         for (int i = 0; i < stringRepeatCount; i++) {
  27.             outputString += stringToRepeat;
  28.         }
  29.         return outputString;
  30.     }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement