10:03 am - Wednesday November 21, 2018

Java Example Program to display * as Traingle

CANDID INDUSTRIAL TRAINING -- CHENNAI
Corporate Training for Experienced Candidate
Struts | Hibernate | Spring | Java / J2EE
SOAP | RestFull | Design Pattern | more...
Ph: +91 72000 69003
137b, 2nd st, shanthi nagar, Chrompet, Chennai -600044
//program for display * as triangle
/**
*@ author:candid.java
*@ description:diaplay * as in triangle shape
**/
class StarTriangle
{
public static void main(String args[])
{
String str="*",space="";
int i,j;
int imax,jmax;//assign maximum range for row and column
imax=jmax=20; // change this value for maximize  triangle
for(i=1;i<=imax;i++)
{
for(j=jmax;j>=1;j--)
{
space=space.concat(" ");//copy " " to space
}

System.out.println(space+str);
str=str.concat("**");//copy ** to str
jmax--;//decrement column value
space="";
}
}
}


output:
       *
      ***
     *****
    *******
   *********
  ***********
 *************
***************

Filed in: Z-A All Java Codes

Comments are closed.