Need some helping hands here !!!

09/26/2011 11:42 zepolzirk#1
What is the source code for this output in JAVA Language?

Sample output:

Enter a Number:
5

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

it should be like this. don't know how to do it. Sorry i'm just studying this for school purpose and badly need this.

this is my source code:

import java.io.*;
public class lopezKrizar_Triangle{
public static void main (String[]args)throws IOException{
DataInputStream kriz=new DataInputStream (System.in);
int ctr;
int ctr2;
int num;


System.out.print ("Enter a Number: ");
num=Integer.parseInt (kriz.readLine());

for (ctr=0;ctr<=num;ctr++)
{
System.out.println();
for (ctr2=0;ctr2<ctr;ctr2++)
{
System.out.print("*");
}


}


}
}

and this is only the output of mine :(

Enter a number:5
*
**
***
****
*****

help ! :(
09/26/2011 13:26 Muddy Waters#2
I'm not really into Java, but since it's all just some simple loops, this should do the trick:
Code:
for(int i = 0; i <= 2*num - 1; i++)
{
	System.out.println();
	for(int j = 0; j < i; j++)
	{
        	System.out.print("*");

        	if(j >= 2*num - 1 - i)
			break;
	}
}