Go to Top

Friday, 27 May 2011

To print a pattern in Java

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

1
22
333
4444
55555

Java Program : 


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

Output : 


1
22
333
4444
55555

Note : Use the calculator and the notepad provided, at the top, to dry run the program.

47 comments:

  1. really helpfull

    ReplyDelete
  2. #####
    #@@@#
    #@@@#
    #@@@#
    #####
    please solve it

    ReplyDelete
  3. Hi Aman ! Here's your program. Be sure to contact me again through comments if there are any mistakes and like this blog on facebook. Visit the link below :

    http://icse-java.blogspot.com/2012/01/visitors-request-3.html

    ReplyDelete
  4. 1
    12
    123
    234
    3451
    45123 plzzz solve it

    ReplyDelete
    Replies
    1. There seems to be a problem with your pattern. Please review it and send it to me again at this e-mail address :

      icse.java.blogspot@gmail.com

      Delete
  5. tell me is there any way that i could low the graphics of a particular game so that i could play it on my computer because every tome i install a game it gave an error that pixel shader 2.0 not found.

    ReplyDelete
  6. write a program to print the first 20 no. of the following pattern:-
    1,3,6,11,20...

    ReplyDelete
    Replies
    1. Your question might be a bit wrong. Since difference between 1 & 3 = 2, 3 & 6 = 3, 6 & 11 = 5, 11 & 20 = 9 <===. The last term should be 18. Also please find out the next term of it if you can, because the next difference might be 9, if taking the odd number logic and 11 if taking the prime number logic. If you think that the question is right, please reply.

      Delete
  7. how to print this:_

    1
    1 1
    1 2 1
    1 3 3 1
    1 4 6 4 1

    ReplyDelete
    Replies
    1. http://icse-java.blogspot.in/2012/02/visitors-request-6.html

      That's your program.

      Delete
  8. 1.W.A.P. to Calculate LCM of n numbers and HCM of n numbers using array.

    ReplyDelete
  9. w.a.p. to perform Linear Search.

    ReplyDelete
    Replies
    1. import java.io.*;
      public class LinearSearch
      {
      int Array[]=new int[10];
      int i,no,flag;
      InputStreamReader in = new InputStreamReader(System.in);
      BufferedReader br =new BufferedReader(in);
      public void accept()throws IOException
      {

      System.out.println("Enter 10 numbers");
      for(i=0;i<10;i++)
      {
      Array[i]=Integer.parseInt(br.readLine());
      }
      }
      public void search()throws IOException
      {
      flag=0;
      System.out.println("Enter the number you want to search");
      no=Integer.parseInt(br.readLine());
      for(i=0;i<10;i++)
      {
      if(no==Array[i])
      {
      flag=1;
      break;
      }
      }
      if(flag==1)
      System.out.println(no+" is found at position "+(i+1));
      else
      System.out.println("Search unsuccessful");
      }
      public void main() throws IOException
      {
      LinearSearch A=new LinearSearch();
      A.accept();
      A.search();
      }
      }

      Delete
  10. WAP to print
    55555
    4444
    333
    22
    1

    ReplyDelete
    Replies
    1. class deep
      {
      public static void main
      {int a=5
      for(int i=5;i>=5;i--)
      {
      for(int j=1;j>=;j--)
      {System.out.print(a);
      }system.out.println();a--;}}}

      Delete
    2. import java util.*;
      class pattern
      {
      public static void main(String arg[])
      {
      int i,n,j;
      n=1;
      for (i=5;i>=n;i--)
      {
      for(j=5;j>=i;j--)
      {
      System.out.print(j);
      }
      System.out. println(i);
      }
      }
      }

      Delete
  11. 1
    121
    12321
    1234321
    plz help me out with this!!

    ReplyDelete
  12. 1
    111
    11111
    111
    1
    how to prit this

    ReplyDelete
    Replies
    1. import java.io.*;
      public class pattern
      {
      int r,c,a;
      public void main() throws IOException
      {
      InputStreamReader in=new InputStreamReader(System.in);
      BufferedReader br=new BufferedReader (in);
      System.out.println("Enter the no. of rows you want");
      a=Integer.parseInt(br.readLine());
      System.out.println();
      for(r=1;r<=a;r++)
      {
      for(c=1;c<=r;c++)
      System.out.print("1 " );
      System.out.println();
      }
      for(r=a-1;r>=1;r--)
      {
      for(c=1;c<=r;c++)
      System.out.print("1 ");
      System.out.println();
      }
      }
      }

      Delete
  13. print this pattern plzzz

    0
    01
    024
    0369
    0481216
    05101520
    061218243036
    07142128354249
    0816243240485664
    091827364554637281

    plzzzz solve it

    ReplyDelete
    Replies
    1. import java.io.*;
      public class pattern
      {
      int r,m,a;
      public void main() throws IOException
      {
      InputStreamReader in=new InputStreamReader(System.in);
      BufferedReader br=new BufferedReader (in);
      System.out.println("Enter the no. of rows you want");
      a=Integer.parseInt(br.readLine());
      System.out.println();
      for(r=1;r<=a;r++)
      {
      System.out.print("0");
      for(m=1;m<=r;m++)
      System.out.print(r*m);
      System.out.println();
      }
      }
      }

      Delete
  14. print
    123454321
    1234 4321
    123 321
    12 21
    1 1

    ReplyDelete
    Replies
    1. import java.io.*;
      public class pattern
      {
      public void main() throws IOException
      {
      InputStreamReader in = new InputStreamReader(System.in);
      BufferedReader br =new BufferedReader(in);
      int r,c,sp=2,s;
      System.out.println("Enter the no of rows you want");
      int n=Integer.parseInt(br.readLine());
      for(r=1;r<=n-1;r++)
      System.out.print(r+" ");
      for(r=n;r>=1;r--)
      System.out.print(r+" ");
      System.out.println();
      for(r=n-1;r>=1;r--)
      {
      for(c=1;c<=r;c++)
      System.out.print(c+" ");
      for(s=sp;s>=1;s--)
      System.out.print(" ");
      for(c=r;c>=1;c--)
      System.out.print(c+" ");
      System.out.println();
      sp=sp+4;
      }
      }
      }

      Delete
  15. pls solve this..

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

    ReplyDelete
  16. plz help to print this

    5432112345
    5432 2345
    543 345
    54 45
    5 5

    ReplyDelete
    Replies
    1. import java.io.*;
      public class pattern
      {public void main() throws IOException
      {
      InputStreamReader in = new InputStreamReader(System.in);
      BufferedReader br =new BufferedReader(in);
      int r,c,sp=0,s;
      System.out.println("Enter the no of rows you want");
      int n=Integer.parseInt(br.readLine());
      System.out.println();
      for(r=1;r<=n;r++)
      {
      for(c=n;c>=r;c--)
      System.out.print(c+" ");
      for(s=sp;s>=1;s--)
      System.out.print(" ");
      for(c=r;c<=n;c++)
      System.out.print(c+" ");
      System.out.println();
      sp=sp+4;
      }

      }
      }

      Delete
  17. *
    * * *
    * * * * *
    * * * * * * *
    * * * * *
    * * *
    *
    hey guys i need this to be printed can anyone solve this plssssssssss
    thanks in advance

    ReplyDelete
    Replies
    1. import java.io.*;
      public class pattern
      {
      int r,c;
      public void main() throws IOException
      {
      InputStreamReader in=new InputStreamReader(System.in);
      BufferedReader br=new BufferedReader (in);
      for(r=1;r<=4;r++)
      {
      for(c=1;c<=r;c++)
      System.out.print("* " );
      System.out.println();
      }
      for(r=3;r>=1;r--)
      {
      for(c=1;c<=r;c++)
      System.out.print("* ");
      System.out.println();
      }
      }
      }

      Delete
  18. How to print this?
    1
    121
    12321
    1234321
    123454321
    1234321
    12321
    121
    1
    This is when n=9.

    ReplyDelete
    Replies
    1. import java.io.*;
      public class pattern
      {
      public void main()throws IOException
      {
      int r,c,a;
      InputStreamReader in = new InputStreamReader(System.in);
      BufferedReader br =new BufferedReader(in);
      System.out.println("How many rows do you want?");
      a=Integer.parseInt(br.readLine());
      for(r=1;r<=a;r++)
      {
      for (c=1;c<=r;c++)
      System.out.print(c+" ");
      for(c=r-1;c>=1;c--)
      System.out.print(c+" ");
      System.out.println();
      }
      for(r=a-1;r>=1;r--)
      {
      for (c=1;c<=r;c++)
      System.out.print(c+" ");
      for(c=r-1;c>=1;c--)
      System.out.print(c+" ");
      System.out.println();
      }
      }
      }

      Delete
  19. a1
    a2 b3
    a4 b5 c6
    a7 b8 c9 d10
    plz solve it..

    ReplyDelete
    Replies
    1. import java.io.*;
      public class pattern
      {
      public void main() throws IOException
      {
      InputStreamReader in = new InputStreamReader(System.in);
      BufferedReader br =new BufferedReader(in);
      int r,c,sum=1,s;
      System.out.println("Enter the no of rows you want");
      int n=Integer.parseInt(br.readLine());
      for(r=1;r<=n;r++)
      {
      sum+=r;
      s=sum-r;
      for(c=1;c<=r;c++)
      {

      System.out.print((char)(96+c)+""+s+" ");
      s++;
      }
      System.out.println();
      }
      }
      }

      Delete
  20. plz help me
    987654321
    87654321
    7654321
    654321
    54321
    4321
    321
    21
    1

    ReplyDelete
    Replies
    1. import java.io.*;
      public class pattern
      {
      public void main()throws IOException
      {
      int r,c,a;
      InputStreamReader in = new InputStreamReader(System.in);
      BufferedReader br =new BufferedReader(in);
      System.out.println("How many rows do you want?");
      a=Integer.parseInt(br.readLine());
      for(r=a;r>=1;r--)
      {
      for (c=r;c>=1;c--)
      System.out.print(c+" ");
      System.out.println();
      }
      }
      }

      Delete
  21. get output as
    0
    10
    101
    0101
    01010

    ReplyDelete
  22. how to do it


    555555555
    4444 4444
    333 333
    22 22
    1 1
    22 22
    333 333
    4444 4444
    555555555

    ReplyDelete
    Replies
    1. import java.io.*;
      public class pattern
      {
      public void main() throws IOException
      {
      InputStreamReader in=new InputStreamReader(System.in);
      BufferedReader br=new BufferedReader (in);
      int a,r,c;
      System.out.println("Enter the no. of rows you want");
      a=Integer.parseInt(br.readLine());
      System.out.println();
      for(r=a;r>=1;r--)
      System.out.print(a);
      for(r=a;r>=1;r--)
      System.out.print(a);
      System.out.println();
      for(r=a-1;r>=1;r--)
      {
      for(c=1;c<=r;c++)
      System.out.print(r);
      System.out.print(" ");
      for(c=1;c<=r;c++)
      System.out.print(r);
      System.out.println();
      }
      for(r=2;r<=a-1;r++)
      {
      for(c=1;c<=r;c++)
      System.out.print(r);
      System.out.print(" ");
      for(c=1;c<=r;c++)
      System.out.print(r);
      System.out.println();
      }
      for(r=a;r>=1;r--)
      System.out.print(a);
      for(r=a;r>=1;r--)
      System.out.print(a);
      }
      }

      Delete
  23. please help me with this code:
    00000
    00123
    01357
    025811

    ReplyDelete
  24. * * * * *
    * * * *
    * * *
    * *
    *
    * *
    * * *
    * * * *
    * * * * *

    ReplyDelete
  25. 1 3 5 7 9
    3 5 7 9 1
    5 7 9 1 3
    7 9 1 3 5
    9 1 3 5 7
    plz solve this for me

    ReplyDelete
  26. pls tell me how to print the pattern
    12345
    22345
    33345
    44445
    55555

    ReplyDelete
  27. plz tell me how to print the pattern
    13579
    35791
    57913
    79135
    91357

    ReplyDelete
  28. plz tell he how to print the pattern
    1
    10
    101
    1010
    10101

    ReplyDelete
  29. plz tell me for this one
    WAPto compute charges for sending parcels where the charges are as follows :
    for the first 1kg RS.25
    for additional weight of 500gms or fraction thereof Rs. 10
    Input the weight of a parcel from the user , display the amount to be paid by the customer

    ReplyDelete

ShareThis