Javascript required
Skip to content Skip to sidebar Skip to footer

Draw a Christmas Tree in Java

christmas Tree

Advertisement

Christmas is the festival of lights and gifts. It always comes to give happiness to everyone's life. so why not you can try to print the Christmas Tree Program in Java.

We are here providing two Christmas Tree Pattern Programs, Select your own choice and Print the Christmas tree and celebrate Christmas.

Christmas Tree Pattern Program also called as Xmas Pattern Program.

Christmas Tree Pattern Program 1:

          *        * *       * * *      * * * *     * * * * *    * * * * * *   * * * * * * *  * * * * * * * *        | |        | |        | |        | |        | |        | |        | |

Christmas Pattern Program 1:

import java.util.Scanner;  class xmax_pattern_1{    public static void main(String[] args) {          Scanner sc = new Scanner(System.in);      System.out.println("Enter the height of tree : ");     int h = sc.nextInt();      //beginning of upper part     for(int i = 1;i <= h;i++){        for(int j = h-i;j > 0;j--){         System.out.print(" ");       }        for(int k = 1;k <= i;k++){         System.out.print("* ");       }        System.out.println();     }//end of upper part      //beginning of lower part     for(int i = 1;i <= h-1;i++){        System.out.print(" ");        for(int j = h-3;j > 0;j--){         System.out.print(" ");       }        for(int k = 2;k > 0;k--){         System.out.print("| ");       }        System.out.println();     }// end of lower part   } }

Output:

Enter the height of the tree :  6      *      * *     * * *    * * * *   * * * * *  * * * * * *      | |      | |      | |      | |      | |        

Christmas Tree Pattern Program 2:

          *            * *           * * *          * * * *           * * *          * * * *         * * * * *        * * * * * *         * * * * *        * * * * * *       * * * * * * *      * * * * * * * *       * * * * * * *      * * * * * * * *     * * * * * * * * *    * * * * * * * * * *     * * * * * * * * *    * * * * * * * * * *   * * * * * * * * * * *  * * * * * * * * * * * *          * * * *          * * * *          * * * *          * * * *        

Christmas Pattern Program 2:

import java.util.Scanner;  class xmax_pattern_2{    public static void main(String[] args) {      Scanner sc = new Scanner(System.in);      System.out.println("Enter the height of the Tree : ");      int h = sc.nextInt();      System.out.println("Enter the width of the Tree : ");      int w = sc.nextInt();      int space = w*5;      int x = 1;      for(int a = 1;a <= h;a++){        for(int i = x;i <= w;i++){          for(int j = space;j >= i;j--){            System.out.print(" ");         }          for(int k = 1;k <= i;k++){            System.out.print("* ");         }          System.out.println();       }        x = x+2;       w = w+2;     }      for(int i = 1;i <= 4;i++){        for(int j = space-3;j >= 1;j--){                  System.out.print(" ");       }        for(int k= 1;k <= 4;k++){         System.out.print("* ");       }        System.out.println();     }   } }

Output:

Enter the height of the Tree :  4 Enter the width of the Tree :  3                *                * *               * * *               * * *              * * * *             * * * * *             * * * * *            * * * * * *           * * * * * * *           * * * * * * *          * * * * * * * *         * * * * * * * * *              * * * *              * * * *              * * * *              * * * *        

These pattern programs come to help you building your analytical skill in Java programming so keep testing and keep coding the pattern programs available here.

I hope you will find these Pattern Programs very helpful for your preparation. If you have doubts regarding these programs comment below or directly mail us. We will happy to help you.

🎅 Merry Christmas 🎅

If you need more Pattern Programs for Practice. Please follow the Link: Pattern Programs

Also, find below links useful:

Arrays in Java

Different ways to find the length of the array

Linear search in Java

buckinghamyind1946.blogspot.com

Source: https://dailyjavaconcept.com/christmas-tree-pattern-program/