Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // MERRY Christmas to all
- public class XmasTree {
- public static void main(String[] args) {
- int treeHeight = 11;
- int stemHeight = 5;
- int numberOfSpaces = treeHeight - 1;
- int numberOfStars = 1;
- for (int i = 0; i < treeHeight; i++) {
- for (int j = 0; j < numberOfSpaces; j++) {
- System.out.print(" ");
- }
- for (int j = 0; j < numberOfStars; j++) {
- System.out.print("*");
- }
- numberOfSpaces--;
- numberOfStars += 2;
- System.out.println("");
- }
- numberOfSpaces = treeHeight - 2;
- for (int i = 0; i < stemHeight; i++) {
- for (int j = 0; j < numberOfSpaces; j++) {
- System.out.print(" ");
- }
- for (int j = 0; j < 3; j++) {
- System.out.print("*");
- }
- System.out.println("");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment