Create Christmas Tree Pattern in Java – Step by Step Guide

Christmas Tree Pattern

Christmas just doesn’t feel like Christmas without the decorations. And is it ever really too early to get started? Get your friends and family on your same level of Christmas tree affinity by sharing these fun Christmas tree created from scratch via coding.

According to The Guinness World Records, the tallest cut Christmas tree was a 67.36m (221 ft) Douglas fir setup at the Northgate Shopping Center in Seattle, Washington, USA, in December 1950. The tallest artificial Christmas tree was 72.1m (236.5ft) tall and was made by the Arjuna Ranatunga Social Services (Sri Lanka), in Colombo, Sri Lanka, on 24 December 2016.

Facts about Christmas tree

In this blog we will write a program to print Christmas tree in Java using multiple for loops in easy way.

Solution in Java :

import java.util.Scanner;

public class ChristmasTree {
    public static void main(String[] args) {
        
        //Welcome to technoname.com

        int i,j;
        Scanner sc=new Scanner(System.in);
        System.out.println("Enter height of christmas tree : ");
        int n=sc.nextInt();
        
        //loop to print pyramid
        for(i=0;i<n;i++){
            for(j=n;j>=i;j--){
                System.out.print("  ");
            }
            for(j=0;j<=i;j++){
                System.out.print("* ");
            }
            for(j=0;j<i;j++){
                System.out.print("* ");
            }

            System.out.println("\n ");
        }
        //printing tail of tree
        for(i=0;i<n;i++){

            for(j=0;j<n/2;j++){
                System.out.print("\t");
            }
            System.out.println("| |");
        }
    }
}

Output :

Christmas Tree pattern
Christmas Tree Pattern

Check out other similar pattern coding questions asked in multiple interviews from here.

We have also published list of top rated movies related to Christmas celebration.

Thank you for reading this article so far, if you know some other way to write above programs then you can leave a comment here or mail us at technonamecontact@gmail.com, So anyone can a get chance to publish their code on our website. As a result, one can improve knowledge and spread it to others

Please check most asked programming questions of strings with examples by clicking here, after that you might get a deep knowledge about string operations, in short, it will be helpful in clearing the interview.

For understanding the most important concept of data structures in an easy way you can check this article on our website.

If you like this article, then please share it with your friends and colleagues. If you have any questions or feedback, then please drop a note.

You can also follow us on Twitter for daily updates.

algorithms array Arrays Artificial Intelligence availability zones az900 azure certification cheat sheet christmas cloud computing coder coding coding questions computerscience data structures DCA DCA Coding Questions DSA google hackerrank interview questions iPhone java latestnews management gropus numpy Patterns programming python python compiler Saas Paas Iaas solution SpringBoot Strings tcs TCS DCA tcs dca 2021 TCS Digital tcsdigital tech news technology tech updates trending Wings1

Leave a Reply

Your email address will not be published. Required fields are marked *