Translate

Thursday 5 July 2012

Write java code to print following pattern

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

Solution:
class Pattern3
{
public static void main(String args[]) 
{
for(int i=1;i<6;i++)
{
for(int j=1;j<=i;j++)
{
if(j==1)
{
for(int k=6-i;k>0;k--)
{
System.out.print(" ");
}
}
System.out.print("* ");
}
System.out.println();
}
}
}

4 comments:

  1. A
    A B
    A B C
    A B C D

    I need help to code the above pattern

    ReplyDelete
    Replies
    1. Hello Shaharica Balu.
      As per your request I have uploaded same kind of program on blog.
      In such kind of programs,you have to make use of ASCII values of Characters.
      Just check the code uploaded recently with title "Write java code to print following pattern".
      Thank you

      Delete
  2. ********
    *******
    ******
    *****
    ****
    ***
    **
    *

    i need your help to code the above pattern

    ReplyDelete
    Replies
    1. Hello Tyka.
      I think I have uploaded same kind of program on this blog.
      But for your convenience I am uploading it here.

      class printStar
      {
      public static void main(String abc[])
      {
      for(int i=8;i>0;i--)
      {
      for(int j=1;j<=i;j++)
      {
      System.out.print("*");
      }
      System.out.println();
      }
      }
      }

      Delete