Java Program To Display Christmas Tree
Learn How To Print and Display Christmas Tree in Java Programming Language. This Java Code uses For Loops primarily which makes it much more easier to write a Java Code to Print a Christmas Tree. This program prints Asterisk to draw the X – Max Tree.
Also Read: C Program To Print Map of India
Java Program To Display Christmas Tree
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | import java.io.*; import java.util.*; class Christmas { static int count; private static void drawChristmasTree(int limit) { for(count = 0; count < limit; count++) { triangleShape(count + 1, limit); } } private static void triangleShape(int x, int limit) { int i, j; for(i = 0; i < x; i++) { for(j = 0; j < limit - i - 1; j++) { System.out.print(" "); } for(j = 0; j < i*2+1; j++) { System.out.print("*"); } System.out.println(""); } } public static void main(String[] args) { int set; System.out.println("Enter the Number of Tree Sets:\t"); Scanner sc = new Scanner(System.in); set = sc.nextInt(); drawChristmasTree(set); } } |
Also Read: 5 Ways To Add Two Integers in C Programming
Output

If you have any compilation errors or doubts in this Java Program To Print Christmas Tree, let us know about in the Comment Section below.
Thank you so much. This Java Code to print Christmas Tree program helped me a lot in TCS Codevita competition. It is just so easy to understand.