Step 1: Open your text editor and type the program.

Step 2: Save the file as .java

Step 3: Open cmd and set path for java. [How to set path for java]


Program


class Heart
{
public static void main(String arg[]) 
{
    int a, b, size = 15;

    for (a = size / 2; a <= size; a = a + 2) 
{        
    for (b = 1; b < size - a; b = b + 2)
        System.out.print(" ");   
    for (b = 1; b <= a; b++)
        System.out.print("R");   
    for (b = 1; b <= size - a; b++)
        System.out.print(" ");   
    for (b = 1; b <= a - 1; b++)
        System.out.print("R");
    System.out.print("\n");
    }

    for (a = size; a >= 0; a--) 
{       
    for (b = a; b < size; b++)
        System.out.print(" ");
   for (b = 1; b <= ((a * 2) - 1); b++)
        System.out.print("R");
    System.out.print("\n");
    }
}
}


OUTPUT:



Post a Comment

Previous Post Next Post