A PHP Error was encountered

Severity: Warning

Message: fopen(/tmp/ci_session6g1qj14nevrgojr41v8kao9den3fpt90): failed to open stream: No space left on device

Filename: drivers/Session_files_driver.php

Line Number: 176

Backtrace:

File: /var/www/html/application/controllers/Project.php
Line: 10
Function: __construct

File: /var/www/html/index.php
Line: 311
Function: require_once

A PHP Error was encountered

Severity: Warning

Message: session_start(): Failed to read session data: user (path: /tmp)

Filename: Session/Session.php

Line Number: 143

Backtrace:

File: /var/www/html/application/controllers/Project.php
Line: 10
Function: __construct

File: /var/www/html/index.php
Line: 311
Function: require_once

Heart Shape Pattern using Java | Shiddhant123
Coders Packet

Heart Shape Pattern using Java

By Shiddhant Gupta

In this project, we will learn how to print the heart shape patterns using the Java programming language.

heart

We will learn how to print the heart shape(as shown in the image) using asterisks. The shape and size of the pattern will depend upon the user input. We will print the pattern using for loops.

import java.util.*;
class heart
{
	public static void main(String args[])
	{
		Scanner sc=new Scanner(System.in);
		System.out.print("Enter element : ");
		int n=sc.nextInt();
		for(int i=3;i<=n;i++)
		{
			for(int j=n-i;j>=1;j--)
			{
				System.out.print(" ");
			}
			for(int k=1;k<=i;k++)
			{
				System.out.print("*");
			}
			for(int k=2;k<=i;k++)
			{
				System.out.print("*");
			}
			for(int j=(n-i)*2;j>=1;j--)
			{
				System.out.print(" ");
			}
			for(int k=1;k<=i;k++)
			{
				System.out.print("*");
			}
			for(int k=2;k<=i;k++)
			{
				System.out.print("*");
			}
			System.out.println("");
		}
		for(int i=1;i<=(n*2)-1;i++)
		{
			for(int j=2;j<=i;j++)
			{
				System.out.print(" ");
			}
			for(int k=(n*4)-1;k>=i*2;k--)
			{
				System.out.print("*");
			}
			System.out.println("");
		}
	}
}

Input: 5

Output:

Heart

Download Complete Code

Comments

No comments yet

Download Packet

Reviews Report

Submitted by Shiddhant Gupta (Shiddhant123)

Download packets of source code on Coders Packet