Print the yacht shape

Here given code implementation process.

//  C program for
//  Print the yacht shape
#include <stdio.h>
 // This is display given text of given length
void includeCharacter(char icon, int n)
{
    for (int i = 0; i < n; ++i)
    {
        printf("%c", icon);
    }
}
void printPattern(int n)
{
    printf("\n N : %d  \n\n", n);

    // Print top layer
    for (int i = 0; i < n / 2; ++i)
    {
        includeCharacter(' ', n - i);
        
        for (int j = 0; j <= i; ++j)
        { 
            printf("* ");
        }
        printf("\n");
    }
    // Print bottom layer
    for (int i = 0; i <= n / 2; ++i)
    {
        if (i < n / 4)
        {
            includeCharacter(' ', i);
        }
        else
        {
            includeCharacter('-', i);
        }
        for (int j = i; j <= n; ++j)
        {
           
                printf("* ");
           
        }
        if (i < n / 4)
        {
            includeCharacter(' ', i);
        }
        else
        {
            includeCharacter('-', i);
        }
        printf("\n");
    }
}
int main(int argc, char const *argv[])
{
    // Test
    printPattern(5);
    printPattern(9);
    printPattern(4);
    printPattern(19);
    return 0;
}

Output

 N : 5

     *
    * *
* * * * * *
-* * * * * -
--* * * * --

 N : 9

         *
        * *
       * * *
      * * * *
* * * * * * * * * *
 * * * * * * * * *
--* * * * * * * * --
---* * * * * * * ---
----* * * * * * ----

 N : 4

    *
   * *
* * * * *
-* * * * -
--* * * --

 N : 19

                   *
                  * *
                 * * *
                * * * *
               * * * * *
              * * * * * *
             * * * * * * *
            * * * * * * * *
           * * * * * * * * *
* * * * * * * * * * * * * * * * * * * *
 * * * * * * * * * * * * * * * * * * *
  * * * * * * * * * * * * * * * * * *
   * * * * * * * * * * * * * * * * *
----* * * * * * * * * * * * * * * * ----
-----* * * * * * * * * * * * * * * -----
------* * * * * * * * * * * * * * ------
-------* * * * * * * * * * * * * -------
--------* * * * * * * * * * * * --------
---------* * * * * * * * * * * ---------
/*
    Java Program
    Print the yacht shape
*/
public class Pattern
{
	// This is display given text of given length
	public void includeCharacter(char icon, int n)
	{
		for (int i = 0; i < n; ++i)
		{
			System.out.print(icon);
		}
	}
	public void printPattern(int n)
	{
		System.out.print("\n N : " + n + " \n\n");
		// Print top layer
		for (int i = 0; i < n / 2; ++i)
		{
			includeCharacter(' ', n - i);
			for (int j = 0; j <= i; ++j)
			{
				System.out.print("* ");
			}
			System.out.print("\n");
		}
		// Print bottom layer
		for (int i = 0; i <= n / 2; ++i)
		{
			if (i < n / 4)
			{
				includeCharacter(' ', i);
			}
			else
			{
				includeCharacter('-', i);
			}
			for (int j = i; j <= n; ++j)
			{
				System.out.print("* ");
			}
			if (i < n / 4)
			{
				includeCharacter(' ', i);
			}
			else
			{
				includeCharacter('-', i);
			}
			System.out.print("\n");
		}
	}
	public static void main(String[] args)
	{
		Pattern task = new Pattern();
		// Test
		task.printPattern(5);
		task.printPattern(9);
		task.printPattern(4);
		task.printPattern(19);
	}
}

Output

 N : 5

     *
    * *
* * * * * *
-* * * * * -
--* * * * --

 N : 9

         *
        * *
       * * *
      * * * *
* * * * * * * * * *
 * * * * * * * * *
--* * * * * * * * --
---* * * * * * * ---
----* * * * * * ----

 N : 4

    *
   * *
* * * * *
-* * * * -
--* * * --

 N : 19

                   *
                  * *
                 * * *
                * * * *
               * * * * *
              * * * * * *
             * * * * * * *
            * * * * * * * *
           * * * * * * * * *
* * * * * * * * * * * * * * * * * * * *
 * * * * * * * * * * * * * * * * * * *
  * * * * * * * * * * * * * * * * * *
   * * * * * * * * * * * * * * * * *
----* * * * * * * * * * * * * * * * ----
-----* * * * * * * * * * * * * * * -----
------* * * * * * * * * * * * * * ------
-------* * * * * * * * * * * * * -------
--------* * * * * * * * * * * * --------
---------* * * * * * * * * * * ---------
// Include header file
#include <iostream>

using namespace std;
/*
    C++ Program
    Print the yacht shape
*/
class Pattern
{
	public:
		// This is display given text of given length
		void includeCharacter(char icon, int n)
		{
			for (int i = 0; i < n; ++i)
			{
				cout << icon;
			}
		}
	void printPattern(int n)
	{
		cout << "\n N : " << n << " \n\n";
		// Print top layer
		for (int i = 0; i < n / 2; ++i)
		{
			this->includeCharacter(' ', n - i);
			for (int j = 0; j <= i; ++j)
			{
				cout << "* ";
			}
			cout << "\n";
		}
		// Print bottom layer
		for (int i = 0; i <= n / 2; ++i)
		{
			if (i < n / 4)
			{
				this->includeCharacter(' ', i);
			}
			else
			{
				this->includeCharacter('-', i);
			}
			for (int j = i; j <= n; ++j)
			{
				cout << "* ";
			}
			if (i < n / 4)
			{
				this->includeCharacter(' ', i);
			}
			else
			{
				this->includeCharacter('-', i);
			}
			cout << "\n";
		}
	}
};
int main()
{
	Pattern *task = new Pattern();
	// Test
	task->printPattern(5);
	task->printPattern(9);
	task->printPattern(4);
	task->printPattern(19);
	return 0;
}

Output

 N : 5

     *
    * *
* * * * * *
-* * * * * -
--* * * * --

 N : 9

         *
        * *
       * * *
      * * * *
* * * * * * * * * *
 * * * * * * * * *
--* * * * * * * * --
---* * * * * * * ---
----* * * * * * ----

 N : 4

    *
   * *
* * * * *
-* * * * -
--* * * --

 N : 19

                   *
                  * *
                 * * *
                * * * *
               * * * * *
              * * * * * *
             * * * * * * *
            * * * * * * * *
           * * * * * * * * *
* * * * * * * * * * * * * * * * * * * *
 * * * * * * * * * * * * * * * * * * *
  * * * * * * * * * * * * * * * * * *
   * * * * * * * * * * * * * * * * *
----* * * * * * * * * * * * * * * * ----
-----* * * * * * * * * * * * * * * -----
------* * * * * * * * * * * * * * ------
-------* * * * * * * * * * * * * -------
--------* * * * * * * * * * * * --------
---------* * * * * * * * * * * ---------
// Include namespace system
using System;
/*
    Csharp Program
    Print the yacht shape
*/
public class Pattern
{
	// This is display given text of given length
	public void includeCharacter(char icon, int n)
	{
		for (int i = 0; i < n; ++i)
		{
			Console.Write(icon);
		}
	}
	public void printPattern(int n)
	{
		Console.Write("\n N : " + n + " \n\n");
		// Print top layer
		for (int i = 0; i < n / 2; ++i)
		{
			this.includeCharacter(' ', n - i);
			for (int j = 0; j <= i; ++j)
			{
				Console.Write("* ");
			}
			Console.Write("\n");
		}
		// Print bottom layer
		for (int i = 0; i <= n / 2; ++i)
		{
			if (i < n / 4)
			{
				this.includeCharacter(' ', i);
			}
			else
			{
				this.includeCharacter('-', i);
			}
			for (int j = i; j <= n; ++j)
			{
				Console.Write("* ");
			}
			if (i < n / 4)
			{
				this.includeCharacter(' ', i);
			}
			else
			{
				this.includeCharacter('-', i);
			}
			Console.Write("\n");
		}
	}
	public static void Main(String[] args)
	{
		Pattern task = new Pattern();
		// Test
		task.printPattern(5);
		task.printPattern(9);
		task.printPattern(4);
		task.printPattern(19);
	}
}

Output

 N : 5

     *
    * *
* * * * * *
-* * * * * -
--* * * * --

 N : 9

         *
        * *
       * * *
      * * * *
* * * * * * * * * *
 * * * * * * * * *
--* * * * * * * * --
---* * * * * * * ---
----* * * * * * ----

 N : 4

    *
   * *
* * * * *
-* * * * -
--* * * --

 N : 19

                   *
                  * *
                 * * *
                * * * *
               * * * * *
              * * * * * *
             * * * * * * *
            * * * * * * * *
           * * * * * * * * *
* * * * * * * * * * * * * * * * * * * *
 * * * * * * * * * * * * * * * * * * *
  * * * * * * * * * * * * * * * * * *
   * * * * * * * * * * * * * * * * *
----* * * * * * * * * * * * * * * * ----
-----* * * * * * * * * * * * * * * -----
------* * * * * * * * * * * * * * ------
-------* * * * * * * * * * * * * -------
--------* * * * * * * * * * * * --------
---------* * * * * * * * * * * ---------
package main
import "fmt"
/*
    Go Program
    Print the yacht shape
*/
type Pattern struct {}
func getPattern() * Pattern {
	var me *Pattern = &Pattern {}
	return me
}
// This is display given text of given length
func(this Pattern) includeCharacter(icon byte, n int) {
	for i := 0 ; i < n ; i++ {
		fmt.Print(string(icon))
	}
}
func(this Pattern) printPattern(n int) {
	fmt.Print("\n N : ", n, " \n\n")
	// Print top layer
	for i := 0 ; i < n / 2 ; i++ {
		this.includeCharacter(' ', n - i)
		for j := 0 ; j <= i ; j++ {
			fmt.Print("* ")
		}
		fmt.Print("\n")
	}
	// Print bottom layer
	for i := 0 ; i <= n / 2 ; i++ {
		if i < n / 4 {
			this.includeCharacter(' ', i)
		} else {
			this.includeCharacter('-', i)
		}
		for j := i ; j <= n ; j++ {
			fmt.Print("* ")
		}
		if i < n / 4 {
			this.includeCharacter(' ', i)
		} else {
			this.includeCharacter('-', i)
		}
		fmt.Print("\n")
	}
}
func main() {
	var task * Pattern = getPattern()
	// Test
	task.printPattern(5)
	task.printPattern(9)
	task.printPattern(4)
	task.printPattern(19)
}

Output

 N : 5

     *
    * *
* * * * * *
-* * * * * -
--* * * * --

 N : 9

         *
        * *
       * * *
      * * * *
* * * * * * * * * *
 * * * * * * * * *
--* * * * * * * * --
---* * * * * * * ---
----* * * * * * ----

 N : 4

    *
   * *
* * * * *
-* * * * -
--* * * --

 N : 19

                   *
                  * *
                 * * *
                * * * *
               * * * * *
              * * * * * *
             * * * * * * *
            * * * * * * * *
           * * * * * * * * *
* * * * * * * * * * * * * * * * * * * *
 * * * * * * * * * * * * * * * * * * *
  * * * * * * * * * * * * * * * * * *
   * * * * * * * * * * * * * * * * *
----* * * * * * * * * * * * * * * * ----
-----* * * * * * * * * * * * * * * -----
------* * * * * * * * * * * * * * ------
-------* * * * * * * * * * * * * -------
--------* * * * * * * * * * * * --------
---------* * * * * * * * * * * ---------
<?php
/*
    Php Program
    Print the yacht shape
*/
class Pattern
{
	// This is display given text of given length
	public	function includeCharacter($icon, $n)
	{
		for ($i = 0; $i < $n; ++$i)
		{
			echo($icon);
		}
	}
	public	function printPattern($n)
	{
		echo("\n N : ".$n." \n\n");
		// Print top layer
		for ($i = 0; $i < (int)($n / 2); ++$i)
		{
			$this->includeCharacter(' ', $n - $i);
			for ($j = 0; $j <= $i; ++$j)
			{
				echo("* ");
			}
			echo("\n");
		}
		// Print bottom layer
		for ($i = 0; $i <= (int)($n / 2); ++$i)
		{
			if ($i < (int)($n / 4))
			{
				$this->includeCharacter(' ', $i);
			}
			else
			{
				$this->includeCharacter('-', $i);
			}
			for ($j = $i; $j <= $n; ++$j)
			{
				echo("* ");
			}
			if ($i < (int)($n / 4))
			{
				$this->includeCharacter(' ', $i);
			}
			else
			{
				$this->includeCharacter('-', $i);
			}
			echo("\n");
		}
	}
}

function main()
{
	$task = new Pattern();
	// Test
	$task->printPattern(5);
	$task->printPattern(9);
	$task->printPattern(4);
	$task->printPattern(19);
}
main();

Output

 N : 5

     *
    * *
* * * * * *
-* * * * * -
--* * * * --

 N : 9

         *
        * *
       * * *
      * * * *
* * * * * * * * * *
 * * * * * * * * *
--* * * * * * * * --
---* * * * * * * ---
----* * * * * * ----

 N : 4

    *
   * *
* * * * *
-* * * * -
--* * * --

 N : 19

                   *
                  * *
                 * * *
                * * * *
               * * * * *
              * * * * * *
             * * * * * * *
            * * * * * * * *
           * * * * * * * * *
* * * * * * * * * * * * * * * * * * * *
 * * * * * * * * * * * * * * * * * * *
  * * * * * * * * * * * * * * * * * *
   * * * * * * * * * * * * * * * * *
----* * * * * * * * * * * * * * * * ----
-----* * * * * * * * * * * * * * * -----
------* * * * * * * * * * * * * * ------
-------* * * * * * * * * * * * * -------
--------* * * * * * * * * * * * --------
---------* * * * * * * * * * * ---------
/*
    Node JS Program
    Print the yacht shape
*/
class Pattern
{
	// This is display given text of given length
	includeCharacter(icon, n)
	{
		for (var i = 0; i < n; ++i)
		{
			process.stdout.write(icon);
		}
	}
	printPattern(n)
	{
		process.stdout.write("\n N : " + n + " \n\n");
		// Print top layer
		for (var i = 0; i < parseInt(n / 2); ++i)
		{
			this.includeCharacter(' ', n - i);
			for (var j = 0; j <= i; ++j)
			{
				process.stdout.write("* ");
			}
			process.stdout.write("\n");
		}
		// Print bottom layer
		for (var i = 0; i <= parseInt(n / 2); ++i)
		{
			if (i < parseInt(n / 4))
			{
				this.includeCharacter(' ', i);
			}
			else
			{
				this.includeCharacter('-', i);
			}
			for (var j = i; j <= n; ++j)
			{
				process.stdout.write("* ");
			}
			if (i < parseInt(n / 4))
			{
				this.includeCharacter(' ', i);
			}
			else
			{
				this.includeCharacter('-', i);
			}
			process.stdout.write("\n");
		}
	}
}

function main()
{
	var task = new Pattern();
	// Test
	task.printPattern(5);
	task.printPattern(9);
	task.printPattern(4);
	task.printPattern(19);
}
main();

Output

 N : 5

     *
    * *
* * * * * *
-* * * * * -
--* * * * --

 N : 9

         *
        * *
       * * *
      * * * *
* * * * * * * * * *
 * * * * * * * * *
--* * * * * * * * --
---* * * * * * * ---
----* * * * * * ----

 N : 4

    *
   * *
* * * * *
-* * * * -
--* * * --

 N : 19

                   *
                  * *
                 * * *
                * * * *
               * * * * *
              * * * * * *
             * * * * * * *
            * * * * * * * *
           * * * * * * * * *
* * * * * * * * * * * * * * * * * * * *
 * * * * * * * * * * * * * * * * * * *
  * * * * * * * * * * * * * * * * * *
   * * * * * * * * * * * * * * * * *
----* * * * * * * * * * * * * * * * ----
-----* * * * * * * * * * * * * * * -----
------* * * * * * * * * * * * * * ------
-------* * * * * * * * * * * * * -------
--------* * * * * * * * * * * * --------
---------* * * * * * * * * * * ---------
#    Python 3 Program
#    Print the yacht shape
class Pattern :
	#  This is display given text of given length
	def includeCharacter(self, icon, n) :
		i = 0
		while (i < n) :
			print(icon, end = "")
			i += 1
		
	
	def printPattern(self, n) :
		print("\n N : ", n ," \n")
		i = 0
		#  Print top layer
		while (i < int(n / 2)) :
			self.includeCharacter(' ', n - i)
			j = 0
			while (j <= i) :
				print("* ", end = "")
				j += 1
			
			print(end = "\n")
			i += 1
		
		i = 0
		#  Print bottom layer
		while (i <= int(n / 2)) :
			if (i < int(n / 4)) :
				self.includeCharacter(' ', i)
			else :
				self.includeCharacter('-', i)
			
			j = i
			while (j <= n) :
				print("* ", end = "")
				j += 1
			
			if (i < int(n / 4)) :
				self.includeCharacter(' ', i)
			else :
				self.includeCharacter('-', i)
			
			print(end = "\n")
			i += 1
		
	

def main() :
	task = Pattern()
	#  Test
	task.printPattern(5)
	task.printPattern(9)
	task.printPattern(4)
	task.printPattern(19)

if __name__ == "__main__": main()

Output

 N :  5

     *
    * *
* * * * * *
-* * * * * -
--* * * * --

 N :  9

         *
        * *
       * * *
      * * * *
* * * * * * * * * *
 * * * * * * * * *
--* * * * * * * * --
---* * * * * * * ---
----* * * * * * ----

 N :  4

    *
   * *
* * * * *
-* * * * -
--* * * --

 N :  19

                   *
                  * *
                 * * *
                * * * *
               * * * * *
              * * * * * *
             * * * * * * *
            * * * * * * * *
           * * * * * * * * *
* * * * * * * * * * * * * * * * * * * *
 * * * * * * * * * * * * * * * * * * *
  * * * * * * * * * * * * * * * * * *
   * * * * * * * * * * * * * * * * *
----* * * * * * * * * * * * * * * * ----
-----* * * * * * * * * * * * * * * -----
------* * * * * * * * * * * * * * ------
-------* * * * * * * * * * * * * -------
--------* * * * * * * * * * * * --------
---------* * * * * * * * * * * ---------
#    Ruby Program
#    Print the yacht shape
class Pattern 
	#  This is display given text of given length
	def includeCharacter(icon, n) 
		i = 0
		while (i < n) 
			print(icon)
			i += 1
		end

	end

	def printPattern(n) 
		print("\n N : ", n ," \n\n")
		i = 0
		#  Print top layer
		while (i < n / 2) 
			self.includeCharacter(' ', n - i)
			j = 0
			while (j <= i) 
				print("* ")
				j += 1
			end

			print("\n")
			i += 1
		end

		i = 0
		#  Print bottom layer
		while (i <= n / 2) 
			if (i < n / 4) 
				self.includeCharacter(' ', i)
			else
 
				self.includeCharacter('-', i)
			end

			j = i
			while (j <= n) 
				print("* ")
				j += 1
			end

			if (i < n / 4) 
				self.includeCharacter(' ', i)
			else
 
				self.includeCharacter('-', i)
			end

			print("\n")
			i += 1
		end

	end

end

def main() 
	task = Pattern.new()
	#  Test
	task.printPattern(5)
	task.printPattern(9)
	task.printPattern(4)
	task.printPattern(19)
end

main()

Output

 N : 5 

     * 
    * * 
* * * * * * 
-* * * * * -
--* * * * --

 N : 9 

         * 
        * * 
       * * * 
      * * * * 
* * * * * * * * * * 
 * * * * * * * * *  
--* * * * * * * * --
---* * * * * * * ---
----* * * * * * ----

 N : 4 

    * 
   * * 
* * * * * 
-* * * * -
--* * * --

 N : 19 

                   * 
                  * * 
                 * * * 
                * * * * 
               * * * * * 
              * * * * * * 
             * * * * * * * 
            * * * * * * * * 
           * * * * * * * * * 
* * * * * * * * * * * * * * * * * * * * 
 * * * * * * * * * * * * * * * * * * *  
  * * * * * * * * * * * * * * * * * *   
   * * * * * * * * * * * * * * * * *    
----* * * * * * * * * * * * * * * * ----
-----* * * * * * * * * * * * * * * -----
------* * * * * * * * * * * * * * ------
-------* * * * * * * * * * * * * -------
--------* * * * * * * * * * * * --------
---------* * * * * * * * * * * ---------
/*
    Scala Program
    Print the yacht shape
*/
class Pattern()
{
	// This is display given text of given length
	def includeCharacter(icon: Char, n: Int): Unit = {
		var i: Int = 0;
		while (i < n)
		{
			print(icon);
			i += 1;
		}
	}
	def printPattern(n: Int): Unit = {
		print("\n N : " + n + " \n\n");
		var i: Int = 0;
		// Print top layer
		while (i < n / 2)
		{
			includeCharacter(' ', n - i);
			var j: Int = 0;
			while (j <= i)
			{
				print("* ");
				j += 1;
			}
			print("\n");
			i += 1;
		}
		i = 0;
		// Print bottom layer
		while (i <= n / 2)
		{
			if (i < n / 4)
			{
				includeCharacter(' ', i);
			}
			else
			{
				includeCharacter('-', i);
			}
			var j: Int = i;
			while (j <= n)
			{
				print("* ");
				j += 1;
			}
			if (i < n / 4)
			{
				includeCharacter(' ', i);
			}
			else
			{
				includeCharacter('-', i);
			}
			print("\n");
			i += 1;
		}
	}
}
object Main
{
	def main(args: Array[String]): Unit = {
		var task: Pattern = new Pattern();
		// Test
		task.printPattern(5);
		task.printPattern(9);
		task.printPattern(4);
		task.printPattern(19);
	}
}

Output

 N : 5

     *
    * *
* * * * * *
-* * * * * -
--* * * * --

 N : 9

         *
        * *
       * * *
      * * * *
* * * * * * * * * *
 * * * * * * * * *
--* * * * * * * * --
---* * * * * * * ---
----* * * * * * ----

 N : 4

    *
   * *
* * * * *
-* * * * -
--* * * --

 N : 19

                   *
                  * *
                 * * *
                * * * *
               * * * * *
              * * * * * *
             * * * * * * *
            * * * * * * * *
           * * * * * * * * *
* * * * * * * * * * * * * * * * * * * *
 * * * * * * * * * * * * * * * * * * *
  * * * * * * * * * * * * * * * * * *
   * * * * * * * * * * * * * * * * *
----* * * * * * * * * * * * * * * * ----
-----* * * * * * * * * * * * * * * -----
------* * * * * * * * * * * * * * ------
-------* * * * * * * * * * * * * -------
--------* * * * * * * * * * * * --------
---------* * * * * * * * * * * ---------
/*
    Swift 4 Program
    Print the yacht shape
*/
class Pattern
{
	// This is display given text of given length
	func includeCharacter(_ icon: Character, _ n: Int)
	{
		var i: Int = 0;
		while (i < n)
		{
			print(icon, terminator: "");
			i += 1;
		}
	}
	func printPattern(_ n: Int)
	{
		print("\n N : ", n ," \n");
		var i: Int = 0;
		// Print top layer
		while (i < n / 2)
		{
			self.includeCharacter(" ", n - i);
			var j: Int = 0;
			while (j <= i)
			{
				print("* ", terminator: "");
				j += 1;
			}
			print(terminator: "\n");
			i += 1;
		}
		i = 0;
		// Print bottom layer
		while (i <= n / 2)
		{
			if (i < n / 4)
			{
				self.includeCharacter(" ", i);
			}
			else
			{
				self.includeCharacter("-", i);
			}
			var j: Int = i;
			while (j <= n)
			{
				print("* ", terminator: "");
				j += 1;
			}
			if (i < n / 4)
			{
				self.includeCharacter(" ", i);
			}
			else
			{
				self.includeCharacter("-", i);
			}
			print(terminator: "\n");
			i += 1;
		}
	}
}
func main()
{
	let task: Pattern = Pattern();
	// Test
	task.printPattern(5);
	task.printPattern(9);
	task.printPattern(4);
	task.printPattern(19);
}
main();

Output

 N :  5

     *
    * *
* * * * * *
-* * * * * -
--* * * * --

 N :  9

         *
        * *
       * * *
      * * * *
* * * * * * * * * *
 * * * * * * * * *
--* * * * * * * * --
---* * * * * * * ---
----* * * * * * ----

 N :  4

    *
   * *
* * * * *
-* * * * -
--* * * --

 N :  19

                   *
                  * *
                 * * *
                * * * *
               * * * * *
              * * * * * *
             * * * * * * *
            * * * * * * * *
           * * * * * * * * *
* * * * * * * * * * * * * * * * * * * *
 * * * * * * * * * * * * * * * * * * *
  * * * * * * * * * * * * * * * * * *
   * * * * * * * * * * * * * * * * *
----* * * * * * * * * * * * * * * * ----
-----* * * * * * * * * * * * * * * -----
------* * * * * * * * * * * * * * ------
-------* * * * * * * * * * * * * -------
--------* * * * * * * * * * * * --------
---------* * * * * * * * * * * ---------
/*
    Kotlin Program
    Print the yacht shape
*/
class Pattern
{
	// This is display given text of given length
	fun includeCharacter(icon: Char, n: Int): Unit
	{
		var i: Int = 0;
		while (i < n)
		{
			print(icon);
			i += 1;
		}
	}
	fun printPattern(n: Int): Unit
	{
		print("\n N : " + n + " \n\n");
		var i: Int = 0;
		// Print top layer
		while (i < n / 2)
		{
			this.includeCharacter(' ', n - i);
			var j: Int = 0;
			while (j <= i)
			{
				print("* ");
				j += 1;
			}
			print("\n");
			i += 1;
		}
		i = 0;
		// Print bottom layer
		while (i <= n / 2)
		{
			if (i < n / 4)
			{
				this.includeCharacter(' ', i);
			}
			else
			{
				this.includeCharacter('-', i);
			}
			var j: Int = i;
			while (j <= n)
			{
				print("* ");
				j += 1;
			}
			if (i < n / 4)
			{
				this.includeCharacter(' ', i);
			}
			else
			{
				this.includeCharacter('-', i);
			}
			print("\n");
			i += 1;
		}
	}
}
fun main(args: Array < String > ): Unit
{
	val task: Pattern = Pattern();
	// Test
	task.printPattern(5);
	task.printPattern(9);
	task.printPattern(4);
	task.printPattern(19);
}

Output

 N : 5

     *
    * *
* * * * * *
-* * * * * -
--* * * * --

 N : 9

         *
        * *
       * * *
      * * * *
* * * * * * * * * *
 * * * * * * * * *
--* * * * * * * * --
---* * * * * * * ---
----* * * * * * ----

 N : 4

    *
   * *
* * * * *
-* * * * -
--* * * --

 N : 19

                   *
                  * *
                 * * *
                * * * *
               * * * * *
              * * * * * *
             * * * * * * *
            * * * * * * * *
           * * * * * * * * *
* * * * * * * * * * * * * * * * * * * *
 * * * * * * * * * * * * * * * * * * *
  * * * * * * * * * * * * * * * * * *
   * * * * * * * * * * * * * * * * *
----* * * * * * * * * * * * * * * * ----
-----* * * * * * * * * * * * * * * -----
------* * * * * * * * * * * * * * ------
-------* * * * * * * * * * * * * -------
--------* * * * * * * * * * * * --------
---------* * * * * * * * * * * ---------

Please share your knowledge to improve code and content standard. Also submit your doubts, and test case. We improve by your feedback. We will try to resolve your query as soon as possible.

New Comment







© 2021, kalkicode.com, All rights reserved