Go to Top

Monday, 1 August 2011

To print the given pattern

Question 21 : Write a program in Java to print the following pattern : 

11111
2222
333
44
5

Java Program : 

public class pattern_8
{
 public static void main()
 {
     int i,j;
     for(i=1;i<=5;i++)
     {
         for(j=5;j>=i;j--)
         {
             System.out.print(i);
            }
            System.out.print("\n");
        }
    }
}
 

19 comments:

  1. I can't sense you all. Please comment.

    ReplyDelete
  2. You can even put down your class 10 programming questions that you couldn't solve and I'll try it out and if I am successful, I'll post it in my blog as "User's Request" if you like.

    ReplyDelete
  3. how to print pattern with n in parameter list
    1
    121
    12321
    1234321
    123454321
    where n is 5

    ReplyDelete
    Replies
    1. class kilp
      {
      public static void main (int n)
      {
      int j;
      for(int i=1;i<=n;i++)
      {
      for(j=1;j<=i;j++)
      {
      System.out.print (j);
      }
      for(int z=j-1;z>1;z--)
      {
      System.out.print(z-1);

      }

      System.out.println();
      }
      }
      }

      Delete
  4. how to print the following pattern
    1
    10
    101
    1010
    10101

    ReplyDelete
    Replies
    1. class Prog22
      {
      public static void main(String args[])
      {
      int i,j,calc;
      for(i=1;i<=5;i++)
      {
      for(j=0;j<i;j++)
      {
      calc=(i+j)%2;
      System.out.print(calc);
      }
      System.out.println();
      }
      }
      }


      Delete
    2. Another way of doing the code

      import java.io.*;
      class assignment_17
      {
      public static void main ()
      {
      int i, j;
      System.out.println("The Pattern is:");
      for (i=1;i<=5;i++)
      {
      for (j=1;j<=i;j++)
      {
      if (j%2==0)
      System.out.print("0"+ " ");
      else
      System.out.print("1"+ " ");
      }
      System.out.println ();
      }
      }
      }

      Delete
  5. how to print this programme
    $
    ###
    >>>>>
    <<<<<<<<
    ?????????

    ReplyDelete
    Replies
    1. This can be done only by one method:-

      class c
      {
      public static void main()
      {
      for(int i=1;i<=9;i+=2)
      {
      if(i==1)
      {
      System.out.println("$");
      }
      else if(i==3)
      {
      System.out.println("###");
      }
      else if(i==5)
      {
      System.out.println(">>>>>");
      }
      else if(i==7)
      {
      System.out.println("<<<<<<<");
      }
      else if(i==9)
      {
      System.out.println("?????????");
      }
      }
      }
      }

      Delete
  6. Please give me the solution:-

    E
    DE
    CDE
    BCDE
    ABCDE

    ReplyDelete
  7. Please give me the solution:-

    E
    DE
    CDE
    BCDE
    ABCDE

    ReplyDelete
  8. *
    **
    ***
    ****
    ***
    **
    *
    Pls help

    ReplyDelete
    Replies
    1. Here is your requested code I hope it helps

      import java.io.*;
      class asteriskpattern
      {
      public static void main()
      {
      int i, j,k,l;
      for(i=1; i<=5; i++)
      {
      for(j=1; j=1;k--)
      {
      for(l=1;l<=k;l++)
      {
      System.out.print("*");
      }
      System.out.println();
      }
      }
      }

      Delete
  9. can u print this please
    1
    10
    101
    1010
    10101

    ReplyDelete
    Replies
    1. import java.io.*;
      class pattern
      {
      public static void main ()
      {
      int i, j;
      System.out.println("The Pattern is:");
      for (i=1;i<=5;i++)
      {
      for (j=1;j<=i;j++)
      {
      if (j%2==0)
      System.out.print("0"+ " ");
      else
      System.out.print("1"+ " ");
      }
      System.out.println ();
      }
      }
      }

      Delete
  10. This comment has been removed by the author.

    ReplyDelete
  11. class prog1
    {
    static void main()
    {
    char ch='E';
    int n=5;
    char ch1;
    int temp=0;
    for(int i=1;i<=n;i++)
    {

    for(int j=1;j<=i;j++)
    {System.out.print(ch);
    ch+=1;
    temp= (int)ch-(j+1);
    }
    ch=(char)temp;

    System.out.println();
    }
    }
    PS: this is the solution to alok apan's question

    ReplyDelete
  12. Please give the solution
    11
    12 22
    13 23 33
    14 24 34 44
    15 25 35 45 55

    ReplyDelete
  13. 12345
    ABCD
    123
    AB
    1

    ReplyDelete

ShareThis