Go to Top

Saturday, 2 July 2011

To print a given pattern

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

1
12
123
1234
12345

Java Program : 

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

17 comments:

  1. Can you help me with this
    0
    00
    111
    1111

    ReplyDelete
    Replies
    1. This comment has been removed by the author.

      Delete
    2. import java.io.*;
      class ser
      {
      public static void main(String args[])throws IOException
      {
      DataInputStream in=new DataInputStream(System.in);
      int a=1;
      for(int i=1;i<=4;i++)
      {
      for(int j=1;j<=i;j++)
      {
      if(a<=3)
      System.out.print(0);
      else
      System.out.print(1);
      a++;
      }
      System.out.println();
      }
      }
      }

      Delete
    3. Pls help me with the following two programmes

      1. WAP to print the following series:- 2,8,23,821,652,.........n
      2. WAP to accept a sentence from the user and dislay the words the have consecutive alphabets in them.

      Delete
  2. pattern
    - - - 1
    - -1 2
    - 1 2 3
    1 2 3 4

    ReplyDelete
  3. How to print
    1
    &&
    123
    &&&&
    1234

    ReplyDelete
  4. how to print 1+12+123....+n using for loop

    ReplyDelete
  5. please slove this
    * *
    ** **
    *** ***
    *******
    *** ***
    ** **
    * *

    ReplyDelete
  6. Replies
    1. This comment has been removed by the author.

      Delete
    2. Class pattern
      {
      Public static void main()
      {
      int i,j;
      for(i=1;i<=5;i++)
      {
      for(j=i;j<=5;j++)
      {
      System.out.println(j);
      }
      System.out.println(" ");
      }
      }
      }

      Delete
  7. Wap to find the sum of series 1+(1×2)+2+(1×2×3)+3+...9

    ReplyDelete
  8. Any one plz do this program
    1 1
    12 21
    123321

    ReplyDelete

ShareThis