Java Code 2 _ To Print the Heart Shaped Pattern using *
Program:
import java.util.*;
public class Main
{
public static void main(String[] args)
{
Scanner s=new Scanner(System.in);
int n;
System.out.println("Enter n value:");
n=s.nextInt(); // To Get 'n' value
for(int i=n/2;i<=n;i+=2)
{
for(int j=1;j<n-i;j+=2)
{
System.out.print(" ");
}
for(int j=1;j<=i;j++)
{
System.out.print("*");
}
for(int j=1;j<n-i;j++)
{
System.out.print(" ");
}
for(int j=1;j<=i;j++)
{
System.out.print("*");
}
System.out.println();
}
for(int i=n;i>=1;i--)
{
for(int j=i;j<n;j++)
{
System.out.print(" ");
}
for(int j=1;j<=(i*2)-1;j++)
{
System.out.print("*");
}
System.out.println("");
}
}
}
Output:
Thank You ...
**************** The Above code is contributed by Madhaneeswaran P *********************