Q.Write a program to print the following pattern
*
* *
* * *
* * * *
* * * * *
public class HalfTriangle
{
public void pattern(int n)
{
for(int i=1;i<=n;i++) //to define the number of rows
{
for(int j=1;j<=i;j++)
{
System.out.print("* ");
}
System.out.println();
}
} //method
} //class
*
* *
* * *
* * * *
* * * * *
public class HalfTriangle
{
public void pattern(int n)
{
for(int i=1;i<=n;i++) //to define the number of rows
{
for(int j=1;j<=i;j++)
{
System.out.print("* ");
}
System.out.println();
}
} //method
} //class
0 comments:
Post a Comment