This is my program

import java.util.*;

class Triangle
{
public static void main(String Vinod[])
{
int i,j,n;
Scanner sc=new Scanner(System.in);
System.out.print("Enter a height of triangle : ");
n=sc.nextInt();
for(i=1;i<=n;i++)
{
    for(j=1;j<=i;j++)
    {
        System.out.print("*");
    }
    System.out.println();
}
for(j=n;j<=1;j--)
{
    for(i=j;i<=1;i--)
    {
        System.out.print("*");
    }
    System.out.println();
}
}
}

I dont know what to do now

My o/p is this:

*
**
***
****

but i want o/p like this:

*
**
***
****
***
**
*

Recommended Answers

All 2 Replies

The code needs to continue after printing line 6 to print the rest of the lines.

What are the rules for formatting the rest of the lines after the full length line? It could be the reverse of the lines printed before the full length line.

Use a piece of paper and a pencil to draw the lines on and to an analyze what is printed on each line as the line numbers increase.

i found it
i just have to put i>=1 & j>=1 in for loop

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.