Thursday, 16 June 2011

Program to Print Triangle Pattern in java

Q.
           *
      *    *
   *    *    *
*    *    *    * 


Solution :

class triangle
{
public static void main ( String args [ ] )
{
int  i , j , k;

for( i =1 ; i < 5 ; i ++ )
{
for( j =1 ; j <5-i ; j++)
{
System.out.print(" ");
}
for( k =i ; k >0 ; k--)
{
System.out.print("* ");
}
System.out.println(" ");
}
}
}

9 comments:

  1. ITS REAlly helpful

    ReplyDelete
  2. public class tt {
    public static void main(String[] args) {
    for (int i=1; i<10; i += 2)
    {
    for (int k=0; k < (6- i /2); k++)
    {

    System.out.print(" ");
    }
    for (int j=0; j<i; j++)
    {
    System.out.print("*");
    }
    System.out.println("");


    }
    }
    }

    ReplyDelete
  3. Thanks....its helpful..

    ReplyDelete
  4. This comment has been removed by the author.

    ReplyDelete
  5. for(int i=1;i<=num;i++){
    for(int j=num-i;j<num;j++){
    System.out.print("*");
    if(j==num-1){
    for(int k=i;k<=j+1;k+=1){
    System.out.print(" ");
    }
    for(int s=1;s<num-(i-1);s++){
    System.out.print(" ");
    }
    for(int l=num-i;l<num;l++){
    System.out.print("*");
    }
    }
    System.out.println();
    }

    ReplyDelete
  6. Any One give me this code in Java

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


    How to Write this program to Print Star Pattern in Java

    ReplyDelete
    Replies
    1. Really Nice Post to Print Star Pattern in Java Yesterday I visit this blog and i was found lots of helpful information from your side thanks for sharing updated and New Technology related Post.

      Delete
  7. Really Nice Post to Print Star Pattern in Java Yesterday I visit this blog and i was found lots of helpful information from your side thanks for sharing updated and New Technology related Post.

    ReplyDelete