Monday, October 4, 2010

making an inverted half triangle in java using forloop

public class halfinvertertri
{

public static void main (String[] args)
{
String str = "*";
String st = "*";
int row;
int col;

for(row=5;row>0;row--)
{
for(col=1;col<=row;col++)
{
System.out.print(" ");
}

System.out.print(str);
str = str + "*";
System.out.println ("");
}
}
}

OUTPUT WILL BE:


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

try it yourself and try to make an experiment out of this example

No comments:

Post a Comment