Monday, June 7, 2010

Printing Pattern Using Nested Loop In BlueJ


While doing pattern using any program, we have to use nested loop. Here one point to be kept in mind that while using nested loops to form pattern, outer loop controls the rows and the inner loop controls the columns. The designing part of any pattern is solely dependant on inner loop. So the printing part job is always done by the inner loop. After studying the pattern, execute the outer loop to generate rows. But the main job is done by the inner loop. So you have to think very deeply about the inner loop designing.

 Few program on pattern are as follows:
 
123454321
1234 4321
123   321
12     21
1       1

class pt1
{
int i,j,k,m,x;
void show()
{
for(i=0;i< 5;i++)
{
x=1;
for(j=i;j< 5;j++)
System.out.print(x++);
for(k=0;k<  i; k++)
System.out.print(" ");
x=x-1;
for(m=i;m< 5;m++)
System.out.print(x--);
System.out.println();
}
}
public static void main(String args[])
{
pt1 ob=new pt1();
ob.show();
}
}

Download eBook on BlueJ 

This above pattern is displayed using three inner loops inside the outer loop. Outer loop as usual generates the rows. First inner loop displays one digit more than that of the third inner loop. The middle inner loop displays the blank spaces of the pattern. Each time the first inner loop starts with '1' and go on incrementing. When the control leaves the first inner loop the middle inner loop catches the control. Again the third inner loop starts from a value less than 2 of the last value of the loop control variable of first inner loop.

Next program on pattern

1 1
12 3
123 6
1234 10
12345 15
  
class pt1
{
int i,j,k,m,x;
void show()
{
x=0;
for(i=1;i< =5;i++)
{
for(j=1;j< =i;j++)
{
System.out.print(j);
}
x=x+i;
System.out.println(" "+x);
 }
 }
public static void main(String args[])
{
pt1 ob=new pt1();
ob.show();
}
}

 This above program is a typical pattern where the inner loop iteration is not fixed. As the outer loop executes, the inner loop execution increases. At the end of execution of the inner loop each time it prints the sum of the digits of that row with a space. As the inner execution increases after each iteration, outer loop control variable is set in the conditional statement of the inner loop. As the control leaves the inner loop, it prints the sum of the digits.

Next program on pattern

1
1 2 1
1 2 3 2 1
1 2 3 4 3 2 1
  
class pt1
{
int i,j,k,m,x;
void show()
{
for(i=0;i< 4;i++)
{
for(j=i;j< 3;j++)
{
if(j==0)
System.out.print("  ");
else
System.out.print(" ");
}
x=1;
for(k=0;k< =i*2;k++)
{
if(k%2==0)
System.out.print(x++);
else
System.out.print(" ");
}
System.out.print(" ");
x=x-2;
for(m=0; m < i*2; m++)
{
if(m%2==0)
System.out.print(x--);
else
System.out.print(" ");
}
System.out.println();
}
}
public static void main(String args[])
{
pt1 ob=new pt1();
ob.show();
}
}

OR

class pt1
{
int i,j,k,m,x;
void show()
{
for(i=0;i< 4;i++)
{
for(j=i;j< 3;j++)
{
System.out.print(" ");
}
x=1;
for(k=0;k< =i;k++)
{
System.out.print(x++);
 }
x=x-2;
for(m=0; m< i;m++)
{
 System.out.print(x--);
}
System.out.println();
}
}
public static void main(String args[])
{
pt1 ob=new pt1();
ob.show();
}
}

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

class pt1
{
int i,j,k,m,x;
void show()
{
x=7;
for(i=0;i< 4;i++)
{
for(j=0; j < i;j++)
System.out.print(" ");
 for(k=0; k< x;k++)
System.out.print("*");
x=x-2;
for(j=0; j< i;j++)
System.out.print(" ");
System.out.println();
}
 x=1;
for(i=0;i< 4;i++)
{
for(j=i+1;j< 4;j++)
System.out.print(" ");
 for(k=0; k< x;k++)
System.out.print("*");
x=x+2;
for(j=i+1;j< 4;j++)
System.out.print(" ");
System.out.println();
}
 }
public static void main(String args[])
{
pt1 ob=new pt1();
ob.show();
}
}

In this program also, inner loop creates this pattern.  This pattern consists of two nested loops and within each outer loop, the first inner loop prints space at the left side and the second inner loop prints the star symbols. After each iterations, the inner loop execution decreases. The first nested loop prints the pattern upto the single star symbol. The other nested loop prints the lower part of the program. Here the inner loop execution increases after each iterations.
  
This site is on Bluej for icse schools. If you have any doubt in any program, pl. feel free to put your comments. I am here to clear your doubts.

305 comments:

  1. print :
    55555
    54444
    54333
    54322
    54321

    ReplyDelete
  2. Two Programs of the above pattern


    class pat
    {
    public static void main(String args[])
    {
    int i,j,k,x;
    for(i=0;i<5;i++)
    {
    x=5;
    for(j=0;j<i;j++)
    System.out.print(x--+" ");
    for(k=i;k<5;k++)
    System.out.print(x+" ");
    System.out.println();
    }
    }
    }


    OR

    class pat
    {
    public static void main(String args[])
    {
    int i,j,x;
    for(i=0;i<5;i++)
    {
    x=5;
    System.out.print(x+" ");
    for(j=0;j<5;j++)
    {
    if(j<i)
    x--;
    System.out.print(x+" ");
    }
    System.out.println();
    }
    }
    }

    ReplyDelete
  3. Oh! A silly mistake in the second program. Modified.....

    class pat
    {
    public static void main(String args[])
    {
    int i,j,x;
    for(i=0;i<5;i++)
    {
    x=5;
    System.out.print(x+" ");
    for(j=0;j<4;j++)
    {
    if(j<i)
    x--;
    System.out.print(x+" ");
    }
    System.out.println();
    }
    }
    }

    ReplyDelete
  4. Solution of the program using BlueJ loop

    import java.io.*;
    class Middle1
    {

    public void display()
    {
    int i,j,n=9;

    for (i=0;i<n/2;i++)
    {

    for(j=i;i<n/2;i++)
    {
    System.out.print(n +" ");
    n--;
    }
    System.out.println();
    }
    }
    }

    ReplyDelete
  5. can ane1 print this pattern??

    7654321
    66
    5 5
    4 4
    3 3
    2 2
    1 1

    ReplyDelete
  6. how to print
    54321
    4321
    321
    21
    1

    ReplyDelete
  7. I am writing the loop statement only, no class or function.

    for(i=5;i>0;i--)
    {
    for(j=i;j>0;j--)
    {
    System.out.print(j);
    }
    System.out.println();
    }

    ReplyDelete
  8. For the pattern
    7654321
    66
    5 5
    4 4
    3 3
    2 2
    1 1

    I have posted the codes on 'Program on Pattern' posted on July 30.

    ReplyDelete
  9. how to print patterns with strings like :
    program
    rogra
    ogr
    g
    ogr
    rogra
    program

    help please !

    ReplyDelete
  10. plz solve

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

    ReplyDelete
  11. Here is the BlueJ program for the pattern:


    class BlueJ
    {
    public static void main(String args[])
    {
    BlueJ ob=new BlueJ();
    ob.display();
    }
    public void display()
    {
    int x=6,y=11,flag;
    for(int i=0;i< 8;i++)
    {
    flag=0;
    for(int j= 1; j<= y; j++)
    {

    if(i==0 || i>=6)
    System.out.print("*");
    else if(j%x==0)
    {
    flag++;
    System.out.print(" ");
    }
    else
    System.out.print("*");
    if( flag==2)
    break;
    }
    if(i<3 && i!=0)
    {

    x--;

    }
    else if(i>=3)
    {
    x++;

    }
    System.out.println();
    }
    }
    }

    ReplyDelete
  12. BlueJ program for the pattern as shown below:


    program
    rogra
    ogr
    g
    ogr
    rogra
    program





    class BlueJ
    {
    public static void main(String args[])
    {
    BlueJ ob=new BlueJ();
    ob.show();
    }
    public void show()
    {
    String str="program";
    int i,j,len,x,y;
    len=str.length();
    x=len;
    y=0;
    for(i= 0;i<len;i++)
    {
    for(j=y;j< x;j++)
    {
    System.out.print(str.charAt(j));
    }
    System.out.println();
    if(i<len/2)
    {
    y++;
    x--;
    }
    else
    {
    y--;
    x++;
    }
    }
    }
    }

    ReplyDelete
  13. plzz solve
    1
    12
    123
    1234
    12345

    ReplyDelete
  14. plzz solv
    *
    ***
    *****
    *******

    ReplyDelete
  15. for the BlueJ program
    1
    12
    123
    1234
    12345


    class BlueJ
    {
    public void show()
    {
    for(int i=1;i<=5;i++)
    {
    for(int j=1;j<=i;j++)
    {
    System.out.print(j);
    }
    System.out.println();
    }
    }
    }


    And For the program

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

    class BlueJ
    {
    public void show()
    {
    for(int i=0;i<4;i++)
    {
    for(int j=0;j<i*2+1;j++)
    {
    System.out.print("*");
    }
    System.out.println();
    }
    }
    }

    ReplyDelete
  16. plz solve fast:
    -1
    -1-2-3
    -1-2-3-4-5

    ReplyDelete
  17. plz help

    1
    123
    12345

    ReplyDelete
  18. class BlueJPatternAnother
    {
    public void show()
    {
    int x=1,y;
    for(int i=1;i<=3;i++)
    {
    y=-1;
    for(int j=1;j<=x;j++)
    {
    System.out.print(y--);
    }
    x=x+2;
    System.out.println();
    }
    }
    public static void main(String args[])
    {
    BlueJPatternAnother ob=new BlueJPatternAnother();
    ob.show();
    }
    }

    ReplyDelete
  19. 1
    123
    12345


    class BlueJPattern
    {
    public void show()
    {
    int x=1;
    for(int i=1;i<=3;i++)
    {
    for(int j=1;j<=x;j++)
    {
    System.out.print(j);
    }
    x=x+2;
    System.out.println();
    }
    }
    public static void main(String args[])
    {
    BlueJPattern ob=new BlueJPattern();
    ob.show();
    }
    }

    ReplyDelete
  20. how to solve
    *
    ***
    *****
    ***
    *

    ReplyDelete
  21. solve this(using ASCII values):-
    A
    AB
    ABC
    ABCD

    ReplyDelete
  22. class BlueJPattern
    {
    public void display()
    {
    int x=1;
    int n=5;
    for(int i=0;i<n;i++)
    {
    for(int j=0;j<x;j++)
    {
    System.out.print("*");
    }
    if(i<n/2)
    x=x+2;
    else
    x=x-2;
    System.out.println();
    }
    }
    }

    ReplyDelete
  23. class BlueJPattern1
    {
    public void show()
    {
    int x=65;
    for(int i=0;i<5;i++)
    {
    for(int j=0;j<=i;j++)
    {
    System.out.print((char)x);
    x++;
    }
    System.out.println();
    }
    }
    }

    ReplyDelete
  24. Ignore the 1st one . for pattern like
    A
    AB
    ABc

    this is the program

    class BlueJPattern1
    {
    public void show()
    {
    int x;
    for(int i=0;i<5;i++)
    {
    x=65;
    for(int j=0;j<=i;j++)
    {
    System.out.print((char)x);
    x++;
    }
    System.out.println();
    }
    }
    }

    ReplyDelete
  25. hey can anyone solve this pattern:

    5 5
    25 7
    125 8
    625 13
    3125 11
    15625 19

    ReplyDelete
  26. Nilotpal, here is the solution of your program.

    class BlueJPattern
    {
    public void show()
    {
    int x=5,sum,f;
    for(int i=0;i<6;i++)
    {
    System.out.print(x+" ");
    sum=0;
    f=x;
    while(f>0)
    {
    sum=sum+f%10;
    f=f/10;
    }
    System.out.print(sum);
    System.out.println();
    x=x*5;
    }
    }
    }

    ReplyDelete
  27. can you create a program with this?
    12345 - 12345
    _1234 - 1234
    __123 - 123
    ___12 - 12
    ____1 - 1

    underscore means SPACE

    or like this
    12345
    1234
    123
    12
    1

    ReplyDelete
  28. 1 0 0 0
    0 1 0 0
    0 0 1 0
    0 0 0 1

    AND

    1 0 0 1
    0 1 1 0
    0 1 1 0
    1 0 0 1

    ReplyDelete
  29. For the pattern

    12345 - 12345
    _1234 - 1234
    __123 - 123
    ___12 - 12
    ____1 – 1

    underscore means SPACE


    BlueJ program

    class BlueJPattern
    {
    public void show()
    {

    for(int i=0;i<5;i++)
    {
    for(int j=1;j<=i;j++)
    System.out.print(" ");
    for(int k=1;k<=5-i;k++)
    System.out.print(k);
    System.out.print(" ");
    for(int m=1;m<=5-i;m++)
    System.out.print(m);
    System.out.println();
    }
    }
    public static void main(String args[])
    {
    BlueJPattern ob=new BlueJPattern();
    ob.show();
    }
    }



    For the pattern
    12345
    1234
    123
    12

    1

    BlueJ program as follows:

    class BlueJPattern
    {
    public void show()
    {

    for(int i=0;i<5;i++)
    {
    for(int k=1;k<=5-i;k++)
    System.out.print(k);
    if(i==4)
    System.out.println();
    System.out.println();

    }
    }
    public static void main(String args[])
    {
    BlueJPattern ob=new BlueJPattern();
    ob.show();
    }
    }

    ReplyDelete
  30. For the pattern

    1 0 0 0
    0 1 0 0
    0 0 1 0
    0 0 0 1

    BlueJ program as follows:

    class BlueJPattern
    {
    public void show()
    {

    for(int i=0;i<4;i++)
    {
    for(int j=0;j<4;j++)
    {
    if(i==j)
    System.out.print("1");
    else
    System.out.print("0");
    }
    System.out.println();
    }
    }
    public static void main(String args[])
    {
    BlueJPattern ob=new BlueJPattern();
    ob.show();
    }
    }

    For the pattern

    1 0 0 1
    0 1 1 0
    0 1 1 0
    1 0 0 1

    BlueJ program as follows:


    class BlueJPattern
    {
    public void show()
    {

    for(int i=0;i<4;i++)
    {
    for(int j=0;j<4;j++)
    {
    if(i==j||i+j==3)
    System.out.print("1");
    else
    System.out.print("0");
    }
    System.out.println();
    }
    }
    public static void main(String args[])
    {
    BlueJPattern ob=new BlueJPattern();
    ob.show();
    }
    }

    ReplyDelete
  31. plz solve-
    12345678910
    13579
    14710
    159
    16
    17
    18
    19
    110
    1

    plz tell what does this program mean and solve it plz !!!

    ReplyDelete
  32. your programs are helping me lots...thankyou so much but pls can u help me with the logic behind the program
    1
    12
    123
    1234
    12345

    ReplyDelete
  33. Thank you Shweta for your complements.
    Well, from the pattern it is clear that it has 5 rows. So the outer loop should run for 5 times as the rows are generated from outer loop.
    In any pattern, rather in nested loops main jobs are always performed from the inner loop. So, here in this pattern the digits are printed from the inner loop. One row print means full course iteration of the inner loop. The inner loop iteration is not fixed in this pattern. The number of inner loop iteration is increased by 1 after each iteration of the outer loop (after each row). We have to set a value in the conditional statement of the inner loop which is increased by 1 after each iteration of the outer loop. The outer loop control variable is increased by one after each iteration, so set it in the conditional statement of the inner loop.
    The values printed are always starting from the same value, so it the inner loop control variable value printed here as we know that in nested loop inner loop always starts from the initial value.

    So the loop is as follows:
    for(int i=1 ; i< 6; i++)
    {
    for( int j=1; j< =i; j++)
    {
    System.out.print(j);
    }
    System.out.println();
    }

    I think the logic is now clear to you.

    ReplyDelete
  34. plss help...i need to slve da following series:

    x/2!+x/4!+x/6!+....n terms

    ReplyDelete
  35. can you pls help me wid da following patern:

    1
    333
    55555
    7777777
    999999999
    7777777
    55555
    333
    1

    ReplyDelete
  36. can anyone pls solve this program...

    1
    2_2
    3_3_3
    4_4_4_4
    5_5_5_5_5
    4_4_4_4
    3_3_3
    2_2
    1

    ReplyDelete
  37. For the above three programs , please refer the post on October 3, 2010

    ReplyDelete
  38. For the pattern
    12345678910
    13579
    14710
    159
    16
    17
    18
    19
    110
    1


    Pl. see the post of October 15

    ReplyDelete
  39. ____1
    ___21
    __321
    _4321
    54321

    ReplyDelete
  40. I need to print out the 10th Fibonacci number only by using for loops

    ReplyDelete
  41. Here is the program to print the 10th fibonacci number


    class BlueJx
    {
    public void show()
    {
    int p=0,c=1,next=0;
    for(int i=0;i<8;i++)
    {
    next=p+c;
    p=c;
    c=next;
    }
    System.out.println("10th element of the series="+next);

    }
    public static void main(String args[])
    {
    BlueJx ob=new BlueJx();
    ob.show();
    }
    }

    ReplyDelete
  42. The other program is



    ____1
    ___21
    __321
    _4321
    54321


    class BlueJx
    {
    public static void main(String args[])
    {
    BlueJx ob=new BlueJx();
    ob.show();
    }
    public void show()
    {
    int x,i,j,k;
    for(i=0;i<5;i++)
    {
    x=5;
    for(j=i+1;j<5;j++)
    {
    x--;
    System.out.print(" ");
    }
    for(k=0;k<=i;k++)
    {
    System.out.print(x--);
    }
    System.out.println();
    }
    }
    }

    ReplyDelete
  43. 1223334445555 what about that code

    ReplyDelete
  44. *****
    * *
    * *
    * *
    *****
    pl help

    ReplyDelete
  45. class BlueJx
    {
    public static void main(String args[])
    {
    BlueJx ob=new BlueJx();
    ob.show();
    }
    public void show()
    {
    int i,j;
    for(i=0;i<5;i++)
    {

    for(j=0;j<5;j++)
    {
    if(i>0 && i<4)
    {
    if(j%2==0)
    System.out.print("*");
    else
    System.out.print(" ");
    if(j==2)
    break;
    }
    else
    System.out.print("*");
    }
    System.out.println();
    }
    }
    }

    ReplyDelete
  46. sir..good day i wanted to know how actually the bluej system analysis and runs the programs..
    i will wait for your reply.....

    ReplyDelete
  47. Hi,Can you Please Show me how to Print Patterns.
    I see them and Get confused and so i score poor in computer.

    ReplyDelete
  48. You send me a program on pattern, I'll clarify each statements through this blog

    ReplyDelete
  49. i wanna learn the concept behind the patern printing

    ReplyDelete
  50. Please go through my post on June 6, 2010- Pattern using nested loop in BlueJ. Very soon I'll post regarding basic logics behind pattern printing.

    ReplyDelete
  51. After writing the codes, we compile the program. Java compiler is a software which checks the statements from top to bottom and if any syntax error is found, it reports. Ultimately compiler converts the source file in to machine code which is a .class file. Then on execution, java interpreter executes the statements.

    ReplyDelete
  52. first print 1 to 10 with the help of arrays and then print it in 10 to 1 (opp order).

    plzzzzzzzzzz solve

    ReplyDelete
  53. Here is the program can be done using do while loop


    class PPatern
    {
    int arr[]={1,2,3,4,5,6,7,8,9};
    int i;
    public void display()
    {
    do
    {
    System.out.print(" "+ arr[i]);
    i++;
    }while(i!=9);

    i--;
    System.out.println();
    do
    {
    System.out.print(" "+ arr[i]);
    i--;
    }while(i>=0);
    }
    }

    ReplyDelete
  54. Your programs have helped me . but i really dont know the logic behind any of these patterns. can you please tell me the logic. i think i have done a big blunder for opting for computer for my class X boards. Please help me

    ReplyDelete
  55. can you please make this pattern:-
    1
    22
    333
    4444
    55555

    also tell me the logic behind this program

    ReplyDelete
  56. This is a simple pattern, I think I have done this program in one of my previous post. Anyway here is the program

    class Pat
    {
    int i,j;
    void show()
    {
    for(i=1; i< 6;i++)
    {
    for( j=1; j< =i;j++)
    {
    System.out.print(i);
    }
    System.out.println();
    }
    }
    }


    Please go through my recent posts in the month od December 2010 regarding basic logics behind pattern printing.

    ReplyDelete
  57. Please go through my recent posts in the month of December 2010 regarding basic logics behind pattern printing.

    ReplyDelete
  58. *
    **
    ***
    ****
    *****

    Can you solve it please by tonight?

    ReplyDelete
  59. I think this type of pattern printing program is already posted in my blog. Please check the pages. Still I am again posting the program

    class A
    {
    int i,j;
    public void display()
    {
    for(i=0;i< 5;i++)
    {
    for(j=0;j< =i;j++)
    {
    System.out.print("*");
    }
    System.out.println();
    }
    }
    public static void main(String args[])
    {
    A ob=new A();
    ob.display();
    }
    }

    ReplyDelete
  60. print dis:
    55555
    55554
    55543
    55432
    54321

    ReplyDelete
  61. Please go through my post on 'Understading inner loop' posted on January 18,2011

    ReplyDelete
  62. pls let me knw how to print this pattern
    1
    222
    33333
    4444444

    ReplyDelete
  63. Here is the program

    class Pat
    {
    int i,n=1,j;
    public void show()
    {
    for(i=1;i<=4;i++)
    {
    for(j=0;j<n;j++)
    {
    System.out.print(i);
    }
    System.out.println();
    n=n+2;
    }
    }
    public static void main(String args[])throws Exception
    {
    Pat obj=new Pat();
    obj.show();
    }
    }

    ReplyDelete
  64. kind sir,u are a big help to me.thank you for your guidance.could you please post a program on merge sort and insertion sort and tell about its logic?
    it will be a great help

    ReplyDelete
  65. Very soon I will post programs on these two sorting techniques. Please be in touch with this site.

    ReplyDelete
  66. Mr. Admin, I just love the way you solve your programs. Straight-forward, simple and easy to follow. I'v been able to understand nested loops from your work.
    I have a problem which I havent been able to solve and I was wondering if you could help me.
    QUE: Using nested loops, print the following pattern -

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

    ReplyDelete
  67. 1 2 3 4 5
    161718196
    152425207
    142322218
    131211109

    ReplyDelete
  68. import java.io.*;
    class smith
    {
    int i,j;
    public void show()
    {
    for(i=0;i<6;i++)
    {
    for(j=1;j<7-i;j++)
    {
    System.out.print(j+" ");
    }
    System.out.println();
    }
    }

    public static void main(String args[])throws IOException
    {
    smith ob=new smith();
    ob.show();
    }

    }

    ReplyDelete
  69. how do you write a program that reads a coded message and decodes it.. the code does not exceed 200 characters ... plz help

    ReplyDelete
  70. Recently I have a program on decoding coded text. I think the program is posted on january.

    ReplyDelete
  71. sir can u plz solve spiral matrix that i had posted above plzzz

    ReplyDelete
  72. 1 2 3 4 5
    16 17 18 19 6
    15 24 25 20 7
    14 23 22 21 8
    13 12 11 10 9

    ReplyDelete
  73. Please refer my post on 19 February 2011

    ReplyDelete
  74. can anyone print d following pattern
    0
    1 2
    3 4 5
    6 7 8 9

    ReplyDelete
  75. class Pattern
    {
    int i,j,x=0;
    public void showPattern()
    {
    for(i=0;i<4;i++)
    {
    for(j=0;j<=i;j++)
    {
    System.out.print(x++);
    }
    System.out.println();
    }
    }
    }

    ReplyDelete
  76. how to print *
    **
    ***
    ****
    *****

    ReplyDelete
  77. can anyone solve dis pattern
    7777777 7777777
    666666 666666
    55555 55555
    4444 4444
    333 333
    22 22
    1 1

    ReplyDelete
  78. can anyone solve this pattern
    11111 11111
    2222 2222
    333 333
    44 44
    5 5

    ReplyDelete
  79. import java.io.*;
    class Pat
    {
    int i,j;
    public void show()
    {
    for(i=7;i>0;i--)
    {
    for(j=0;j<i*2+1;j++)
    {
    if(j==i)
    System.out.print(" ");
    else
    System.out.print(i);
    }
    System.out.println();
    }
    }
    public static void main(String args[])throws Exception
    {
    Pat ob=new Pat();
    ob.show();
    }
    }

    ReplyDelete
  80. Please remove the statement 'import java.io.*;'

    ReplyDelete
  81. for the pattern
    *
    **
    ***
    ****
    *****

    Here is the loop structure
    for(i=0;i<5;i++0
    {
    for(j=0;j<=i;j++)
    {
    System.out.print("*");
    }
    System.out.println();
    }

    ReplyDelete
  82. import java.io.*;
    class Pat
    {
    int i,j,n=6;
    public void show()
    {
    for(i=1;i<n;i++)
    {
    for(j=0;j<n*2+1-i*2;j++)
    {
    if(j==n-i)
    System.out.print(" ");
    else
    System.out.print(i);
    }
    System.out.println();
    }
    }
    public static void main(String args[])throws Exception
    {
    Pat ob=new Pat();
    ob.show();
    }
    }

    ReplyDelete
  83. pls solve this for me

    1
    121
    12321
    1234321
    123454321

    and this one

    *****
    ****1
    ***21
    **321
    *4321
    54321

    ReplyDelete
  84. respected sir...
    which programme is the toughest in blueJ from the syllabus of icse 2011.

    ReplyDelete
  85. Concentrate more on decision making programs, specially switch and else if ladder. Actually tough question can be set from any chapter.

    ReplyDelete
  86. Program no 1:


    class Pat
    {
    int i,j,k,n,m=7;
    /* You take the value of 'm' from user also*/
    public void show()
    {
    for(i=0;i<m;i++)
    {
    n=1;
    for(j=0;j<=i;j++)
    {
    System.out.print(n);
    n++;
    }
    n=n-2;
    for(k=0;k<i;k++)
    {
    System.out.print(n);
    n--;
    }
    System.out.println();
    }
    }
    public static void main(String args[])throws Exception
    {
    Pat ob=new Pat();
    ob.show();
    }
    }

    Program no 2:


    class Pat1
    {
    int i,j,k,n,m=6;
    public void show1()
    {
    for(i=0;i<m;i++)
    {
    n=5;
    for(j=i;j<5;j++)
    {
    System.out.print("*");
    n--;
    }
    for(k=0;k<i;k++)
    {
    System.out.print(n);
    n--;
    }
    System.out.println();
    }
    }
    public static void main(String args[])throws Exception
    {
    Pat1 ob=new Pat1();
    ob.show1();
    }
    }

    ReplyDelete
  87. sir if you dont mind can i ask you how do you get the logic that you have to apply a particular logic to a particular program?sir help me in writing programs

    ReplyDelete
  88. Analysis of a program is must to do any program. Logic development is a long term process. Whenever you get any solved program, read each and every line of codes and try to find out the logic behind the codes because behind every code there must be a logic. If you continue this process, you will be ultimately able to develop your own logic.

    ReplyDelete
  89. thankyou very much sir you r very helpfl to me sir help me tu print
    12345
    51234
    45123
    34512
    23451

    ReplyDelete
  90. Here is the program



    class Pat
    {
    int i,j,n,m=100;
    public void show()
    {
    for(i=0;i<5;i++)
    {
    n=1;
    for(j=0;j<5;j++)
    {
    if(m<=5)
    System.out.print(m++);
    else
    System.out.print(n++);
    }
    m=n-1;
    System.out.println();
    }
    }
    public static void main(String args[])
    {
    Pat ob=new Pat();
    ob.show();
    }
    }

    ReplyDelete
  91. im really hoping you can help me... what do i do in my for loops to do this:
    oooooooooo
    ooooooooo*
    oooooooo**
    ooooooo***
    oooooo****
    ooooo*****
    oooo******
    ooo*******
    oo********
    o*********

    and

    o*********
    oo********
    ooo*******
    oooo******
    ooooo*****
    oooooo****
    ooooooo***
    oooooooo**
    ooooooooo*
    oooooooooo

    ReplyDelete
  92. For the first pattern


    class Pattern
    {

    int i,j,k;
    public void show() throws Exception
    {

    for(i=0;i<10;i++)
    {
    for(j=0;j<10-i;j++)
    System.out.print("o");
    for(k=0;k<i;k++)
    System.out.print("*");
    System.out.println();
    }
    }
    public static void main(String args[]) throws Exception
    {
    Pattern ob=new Pattern ();
    ob.show();
    }
    }



    For the second pattern

    class Pattern1
    {

    int i,j,k;
    public void show() throws Exception
    {

    for(i=0;i<10;i++)
    {
    for(j=0;j<=i;j++)
    System.out.print("o");
    for(k=0;k<10-1-i;k++)
    System.out.print("*");
    System.out.println();
    }
    }
    public static void main(String args[]) throws Exception
    {
    Pattern1 ob=new Pattern1 ();
    ob.show();
    }
    }

    ReplyDelete
  93. in pattern program
    12345
    51234
    45123
    34512
    23451
    sir u hv posted why u hv taken m=100?

    ReplyDelete
  94. 'm=100' is the initial value of 'm'. It can be any value greater than 5 as 'm' is getting the actual value for the first time at the end of loop body.
    Please note the statements:

    for(j=0;j<5;j++)
    {
    if(m<=5)
    System.out.print(m++);
    else
    System.out.print(n++);
    }
    m=n-1;


    If we do not assign any value on 'm' then it will hold default value,0 and the if statement will become true at the first time execution of the loop which is not required for the above pattern.

    ReplyDelete
  95. i would like to ask ur help 4 one of my c++ programming ques :
    use nested loops that print following patterns.
    12345
    1234
    123
    12
    1

    ReplyDelete
  96. Please check cbsetutorial.blogspot.com

    ReplyDelete
  97. Can you please print

    123
    456
    789

    ?
    Thank you!

    ReplyDelete
  98. I am simply function to print the pattern.

    void show()
    {
    int i,j,x=1;
    for(i=0;i< 3;i++)
    {
    for(j=0;j< 3;j++)
    {
    System.out.print(x++);
    }
    System.out.println();
    }
    }

    ReplyDelete
  99. Sir i need a program for the following pattern :
    1
    12
    123
    1234
    123
    12
    1

    ReplyDelete
  100. Sir,
    can you please post a program to print cubes of 20 natural numbers skipping numbers that are divisible by 2 and 3.

    ReplyDelete
  101. class Post
    {
    int i;
    public void show()
    {
    for(i=1;i< =20;i++)
    {
    if(i%2!=0 && i%3!=0)
    System.out.print(" "+ (i*i*i));
    }
    }
    public static void main(String args[])
    {
    Post ob=new Post();
    ob.show();
    }
    }

    ReplyDelete
  102. class Post
    {
    int i,j,x=1;
    public void show()
    {
    for(i=0;i< 7;i++)
    {
    if(i >7/2)
    x--;
    else
    x++;
    for(j=1;j< x;j++)
    {
    System.out.print(j);
    }
    System.out.println();
    }
    }
    public static void main(String args[])
    {
    Post ob=new Post();
    ob.show();
    }
    }

    ReplyDelete
  103. Display the pattern:- 1
    121
    12321
    1234321
    123454321
    1234321
    12321
    121
    1

    ReplyDelete
  104. can you please help me display this pattern:
    aaaaa
    bbbb
    ccc
    dd
    e
    dd
    ccc
    bbbb
    aaaaa

    ReplyDelete
  105. Search my blog, similar programs are posted

    ReplyDelete
  106. class Pat
    {
    int i,j,k,x,y;
    public void show()
    {
    for(i=0; i<9;i++)
    {
    x=1;
    if(i<5)
    y=i;
    else
    y=y-1;
    for(j=0;j<=y;j++)
    {
    System.out.print(x++);
    }
    x=x-2;
    for(k=0;k<y;k++)
    {
    System.out.print(x--);
    }
    System.out.println();
    }
    }
    public static void main(String args[])
    {
    Pat b=new Pat();
    b.show();
    }
    }

    ReplyDelete
  107. class Pat
    {
    int i,j,x=5;
    char ch='a';
    public void show()
    {
    for(i=0; i<9;i++)
    {
    for(j=0;j<x;j++)
    {
    System.out.print(ch);
    }
    if(i<4)
    {
    ch++;
    x--;
    }
    else
    {
    ch--;
    x++;
    }
    System.out.println();
    }
    }
    public static void main(String args[])
    {
    Pat b=new Pat();
    b.show();
    }
    }

    ReplyDelete
  108. Sir,
    I need a program for the following patterns:
    (1)54321
    5432
    543
    54
    5

    (2)5
    54
    543
    5432
    54321

    ReplyDelete
  109. For pattern :

    54321
    5432
    543
    54
    5


    class Pat
    {
    int i,j;
    public void show()
    {
    for(i=5;i>=1;i--)
    {
    for(j=5;j>5-i;j--)
    {
    System.out.print(j);
    }
    System.out.println();
    }
    }
    public static void main(String args[])
    {
    Pat ob=new Pat();
    ob.show();
    }
    }

    For pattern:

    5
    54
    543
    5432
    54321

    class Pat
    {
    int i,j,x=1;
    public void show()
    {
    for(i=5;i>=1;i--)
    {
    for(j=0;j<x;j++)
    {
    System.out.print((5-j));
    }
    x++;
    System.out.println();
    }
    }
    public static void main(String args[])
    {
    Pat ob=new Pat();
    ob.show();
    }
    }

    ReplyDelete
  110. i want to print this pattern...how to do it?
    11111
    22222
    33333
    44444
    55555

    ReplyDelete
  111. class Pattern
    {
    int i,j;
    public void show()
    {
    for(i=1;i < = 5;i++)
    {
    for(j=1; j < =5;j++)
    {
    System.out.print(i);
    }
    System.out.println();
    }
    }
    }

    ReplyDelete
  112. plz help me wid this program:

    1
    212
    32123
    4321234

    ReplyDelete
  113. sir,plzz can you solve this pattern:
    L
    L O
    L O T
    L O T U
    L O T U S
    L O T U
    L O T
    L O
    L

    ReplyDelete
  114. class Lotus
    {
    int i,j,len,x,flag=0;
    String str="LOTUS";
    void show()
    {
    len=str.length();
    x=0;
    for(i=0;i<len*2-1;i++)
    {
    if(x==len)
    flag=1;
    if(flag==0)
    x++;
    else
    x--;
    for(j=0;j<x;j++)
    {
    System.out.print(str.charAt(j));

    }
    System.out.println();
    }
    }
    public static void main(String args[])
    {
    Lotus ob=new Lotus();
    ob.show();
    }
    }

    ReplyDelete
  115. class Pat1
    {
    int i,j,k,x;
    void show()
    {

    for(i=0;i<4;i++)
    {
    x=i+1;
    for(j=0;j<=i;j++)
    {
    System.out.print(x--);
    }
    x=x+2;
    for(k=0;k<i;k++)
    {
    System.out.print(x++);
    }
    System.out.println();
    }
    }
    public static void main(String args[])
    {
    Pat1 ob=new Pat1();
    ob.show();
    }
    }

    ReplyDelete
  116. can u help me in printing these......??
    a)
    ****
    ***
    **
    *
    b)
    *
    **
    ***
    ****
    c)
    *
    ***
    *****
    *******

    ReplyDelete
  117. The three programs are given below:


    public class Pattern1
    {
    int i,j;
    void show()
    {
    for(i=0;i<4;i++)
    {
    for(j=i;j<4;j++)
    {
    System.out.print("*");
    }
    System.out.println();
    }
    }
    public static void main(String args[])
    {
    Pattern1 ob=new Pattern1 ();
    ob.show();
    }
    }


    public class Pattern2
    {
    int i,j;
    void show()
    {
    for(i=0;i<4;i++)
    {
    for(j=0;j<=i;j++)
    {
    System.out.print("*");
    }
    System.out.println();
    }
    }
    public static void main(String args[])
    {
    Pattern2 ob=new Pattern2 ();
    ob.show();
    }
    }

    public class Pattern3
    {
    int i,j,x=1;
    void show()
    {
    for(i=0;i<4;i++)
    {
    for(j=0;j<x;j++)
    {
    System.out.print("*");
    }
    x=x+2;
    System.out.println();
    }
    }
    public static void main(String args[])
    {
    Pattern3 ob=new Pattern3 ();
    ob.show();
    }
    }

    ReplyDelete
  118. please solve the pattern

    B
    L
    B L U E J
    E
    J

    ReplyDelete
  119. how to do pattern
    1. 1AAAA
    22BBB
    333CC
    4444D
    55555

    2. 1
    232
    34543
    4567654
    3. 1
    01
    101
    0101
    10101
    4. a
    ab
    abc
    abcd
    abcde

    Plz reply fast

    ReplyDelete
  120. class Pat
    {
    String str="BLUEJ";
    int i,j;
    void disp()
    {
    int len=str.length();
    for(i=0;i<len;i++)
    {
    if(i==len/2)
    {
    for(j=0;j<len;j++)
    System.out.print(str.charAt(j));
    }
    else
    {
    for(j=i;j<=i;j++)
    System.out.print(str.charAt(j));
    }

    System.out.println();
    }
    }
    }

    ReplyDelete
  121. Here are the programs:


    class Pattern
    {
    public void disp()
    {
    int i,j,k;
    for(i=1;i< =5;i++)
    {
    for(j=1;j< =i;j++)
    {
    System.out.print(i);
    }
    for(k=i;k< 5;k++)
    {
    System.out.print((char)(i+64));
    }
    System.out.println();
    }
    }
    public static void main(String args[])
    {
    Pattern ob=new Pattern();
    ob.disp();
    }
    }



    1
    232
    34543
    4567654


    class Pattern
    {
    public void disp()
    {
    int i,j,k,x;
    for(i=0;i< 4;i++)
    {
    x=i+1;
    for(j=0;j< =i;j++)
    {
    System.out.print(x++);
    }
    x=x-2;
    for(k=0;k< i;k++)
    {
    System.out.print(x--);
    }
    System.out.println();
    }
    }
    public static void main(String args[])
    {
    Pattern ob=new Pattern();
    ob.disp();

    }
    }

    1
    01
    101
    0101
    10101

    class Pattern
    {
    public void disp()
    {
    int i,j;
    for(i=0;i< 5;i++)
    {
    for(j=0;j< =i;j++)
    {
    if((i%2==0 && j%2==0)||(i%2!=0 && j%2!=0))
    System.out.print("1");
    else
    System.out.print("0");
    }
    System.out.println();
    }
    }
    public static void main(String args[])
    {
    Pattern ob=new Pattern();
    ob.disp();

    }
    }

    a
    ab
    abc
    abcd
    abcde


    class Pattern
    {
    public void disp()
    {
    int i,j,x;
    for(i=0;i< 5;i++)
    {
    x=97;
    for(j=0;j< =i;j++)
    {
    System.out.print((char)(x+j));
    }
    System.out.println();
    }
    }
    public static void main(String args[])
    {
    Pattern ob=new Pattern();
    ob.disp();

    }
    }

    ReplyDelete
  122. Please solve:
    2
    5 10
    17 26 37

    ReplyDelete
  123. class A
    {
    int i,j,x=2,y=3;
    public void show()
    {
    for(i=0;i<3;i++)
    {
    for(j=0;j<=i;j++)
    {
    System.out.print(x+ " ");
    x=x+y;
    y=y+2;
    }
    System.out.println();
    }
    }
    }

    ReplyDelete
  124. please solve the following pattern

    c
    o o
    m m m
    p p p p
    u u u u u
    t t t t t t
    e e e e e e e
    r r r r r r r r

    ReplyDelete
  125. C
    O O
    M M M
    P P P P
    U U U U U
    T T T T T T
    E E E E E E E
    R R R R R R R R

    ReplyDelete
  126. Sir can you solve this program:-
    5555
    4444
    3333
    2222
    1111

    ReplyDelete
  127. sir can you plzz print the folloing programs:

    a) 1
    2 3
    4 5 6
    7 8 9 10
    11 12 13 14 15

    b)
    1
    121
    12312
    1234123

    c)
    1
    121
    12312
    1234123
    12321
    121
    1

    ReplyDelete
  128. class Pat
    {
    int i,j;
    public void dis()
    {
    for(i=5;i >0;i--)
    {
    for(j=0;j< 5;j++)
    {
    System.out.print(i);
    }
    System.out.println();
    }
    }
    }

    ReplyDelete
  129. class Comp
    {
    String str="COMPUTER";
    int i,j,len;
    public void show()
    {
    len=str.length();
    for(i=0;i< len;i++)
    {
    for(j=0;j<=i;j++)
    {
    System.out.print(str.charAt(i));
    }
    System.out.println();
    }
    }
    }

    ReplyDelete
  130. class Comp
    {
    String str="computer";
    int i,j,len;
    public void show()
    {
    len=str.length();
    for(i=0;i< len;i++)
    {
    for(j=0;j<=i;j++)
    {
    System.out.print(str.charAt(i));
    }
    System.out.println();
    }
    }
    }

    ReplyDelete
  131. Programs of the programs (a),(b) and (c) are :


    2nd program

    a) public class Bubblesort
    b) {
    c) int i,j,k,x;
    d) public void show()
    e) {
    f) for(i=0;i<4;i++)
    g) {
    h) x=1;
    i) for(j=0;j<=i;j++)
    j) {
    k) System.out.print(x);
    l) x++;
    m) }
    n) x=1;
    o) for(k=0;k=7/2)
    f=1;
    if(f==1)
    n--;
    else
    n++;
    System.out.println();
    }
    }
    }

    ReplyDelete
  132. 2nd program

    public class Bubblesort
    {
    int i,j,k,x;
    public void show()
    {
    for(i=0;i<4;i++)
    {
    x=1;
    for(j=0;j<=i;j++)
    {
    System.out.print(x);
    x++;
    }
    x=1;
    for(k=0;k<i;k++)
    {
    System.out.print(x);
    x++;
    }
    System.out.println();
    }
    }
    }

    ReplyDelete
  133. 1st program

    public class Bubblesort
    {
    int i,j,x=1;
    public void show()
    {
    for(i=0;i<5;i++)
    {
    for(j=0;j<=i;j++)
    {
    System.out.print(x);
    x++;
    }
    System.out.println();
    }
    }



    3rd program

    public class Bubblesort
    {
    int i,j,x,k,n=0,f=0;
    public void show()
    {
    for(i=0;i<7;i++)
    {
    x=1;
    for(j=0;j<=n;j++)
    {
    System.out.print(x);
    x++;
    }
    x=1;
    for(k=0;k=7/2)
    f=1;

    ReplyDelete
  134. I need hellp with this program -

    WAP to input a number and print the sum of first and last digits of that number.

    ReplyDelete
  135. Sir can you please help me with this pattern i will be grateful......
    *****
    ****
    ***
    **
    *

    ReplyDelete
  136. import java.io.*;
    public class Bubblesort
    {
    int s=0,a,b,len;
    String str;
    char ch;
    BufferedReader br=new BufferedReader(new InputStreamReader(System.in));

    public void show()throws Exception
    {
    System.out.println("Enter the number:");
    str=br.readLine();
    len=str.length();
    ch=str.charAt(0);
    a=ch-48;
    ch=str.charAt(len-1);
    b=ch-48;
    a=a+b;
    System.out.println("Sum="+a);
    }
    }

    ReplyDelete
  137. For all the programs a lot of thanks!!!!

    ReplyDelete
  138. class A
    {
    int i,j;
    public void show()
    {
    for(i=0;i<5;i++)
    {
    for(j=i;j<5;j++)
    {
    System.out.print("*");
    }
    System.out.println()'
    }
    }
    }

    ReplyDelete
  139. C
    OO
    MMM
    PPPP
    UUUUU
    TTTTTT
    EEEEEEE
    RRRRRRRR
    SIR, KINDLY PLS TELL ME HOW TO PRINT THIS PATTERN

    ReplyDelete
  140. I think few days back, I have posted similar program.

    class Pat
    {
    String str;
    int i,j,len;
    str="COMPUTER";
    public void showPattern()
    {
    len=str.length();
    for(i=0;i<len;i++)
    {
    for(j=0;j<=i;j++)
    {
    System.out.print(str.charAt(i));
    }
    System.out.println();
    }
    }
    }

    ReplyDelete
  141. 1234554321
    1234 4321
    123 321
    12 21
    1 1
    12 21
    123 321
    1234 4321
    1234554321


    sir please help me out... i beg your pardon

    ReplyDelete
  142. *
    * *
    * *
    * *
    * *
    * *
    *

    please sir solve this one.... i beg your pardon...

    ReplyDelete
  143. Please check this one:


    public class Pattern
    {
    int i,j,k,x,y=5;
    public void show()
    {
    for(i=0;i< 9;i++)
    {
    x=1;
    for(j=0;j< y;j++)
    System.out.print(x++);
    if(i!=0 && i!=8)
    {
    for(j=0;j< 1;j++)
    System.out.print(" ");
    }
    x=x-1;
    for(k=0;k< y;k++)
    System.out.print(x--);
    System.out.println();
    if(i>=9/2)
    y++;
    else
    y--;
    }
    }
    public static void main(String args[])throws Exception
    {
    Pattern ob=new Pattern ();
    ob.show();
    }
    }

    ReplyDelete
  144. "-" SPACE.. FOR INDICATION AS SPACE IS NOT TAKEN
    BY THIS BOXX....

    ----*
    ---*-*
    --*---*
    -*-----*
    --*---*
    ---*-*
    ----*


    plese sir make this one out...

    ReplyDelete
  145. "-" SPACE.. FOR INDICATION AS SPACE IS NOT TAKEN
    BY THIS BOXX....

    ----a
    ---aba
    --abcba
    -abcdcba
    abcdedcba
    -abcdcba
    --abcba
    ---aba
    ----a

    plese solve the above 3 recent programs posted by me... i beg your pardon..

    ReplyDelete
  146. public class Series
    {
    int i,m,n,k,a=0,b=0;
    char x;
    public void show()
    {
    for(i=0;i<9;i++)
    {
    x='a';
    for(k=a;k<4;k++)
    System.out.print(" ");
    for(m=0;m<=b;m++)
    {
    System.out.print(x);
    x=(char)(x+1);
    }
    x=(char)(x-2);
    for(n=0;n<b;n++)
    {
    System.out.print(x);
    x=(char)(x-1);
    }
    System.out.println();
    if(i<9/2)
    {
    a++;
    b++;
    }
    else
    {
    a--;
    b--;
    }
    }
    }

    public static void main(String args[]) throws Exception
    {
    Series ob=new Series();
    ob.show();
    }
    }

    ReplyDelete
  147. *********
    **** ****
    *** ***
    ** **
    * *
    ** **
    *** ***
    **** ****
    *********

    ReplyDelete
  148. public class Pattern
    {
    int i,j,k,y=5;
    public void show()
    {
    for(i=0;i< 9;i++)
    {
    for(j=0;j< y;j++)
    System.out.print("*");
    if(i!=0 && i!=8)
    {
    for(j=0;j< 1;j++)
    System.out.print(" ");
    }

    for(k=0;k< y;k++)
    System.out.print("*");
    System.out.println();
    if(i>=9/2)
    y++;
    else
    y--;
    }
    }
    public static void main(String args[])throws Exception
    {
    Pattern ob=new Pattern ();
    ob.show();
    }
    }

    ReplyDelete
  149. a sincere thanks a lot for all the programs///
    please please do this program////.. "-"-space
    ----*
    ---*-*
    --*---*
    -*-----*
    --*---*
    ---*-*
    ----*

    ReplyDelete
  150. public class Series
    {
    int i,j,k,y=1,x=4,m,n;
    public void show()
    {
    for(i=0;i<7;i++)
    {
    for(k=0;k<x;k++)
    System.out.print(" ");
    for(n=0;n<y;n++)
    {
    if(n==0 || n==y-1)
    System.out.print("*");
    else
    System.out.print(" ");
    }
    System.out.println();
    if(i<7/2)
    {
    x--;
    y=y+2;
    }
    else
    {
    x++;
    y=y-2;
    }
    }
    }
    public static void main(String args[]) throws Exception
    {
    Series ob=new Series();
    ob.show();
    }
    }

    ReplyDelete
  151. 12345 54321

    1234 4321

    123 321

    12 21

    1 1

    12 21

    123 321

    1234 4321

    12345 54321

    sir plz give a solution

    ReplyDelete
    Replies
    1. Already posted, still posting for the second time

      import java.io.*;
      class Arr
      {
      int i,j,x,y=1,k,m,n;
      public void show()
      {
      m=5;
      for (i=0;i<9;i++)
      {
      x=1;
      for(j=0;j<m;j++)
      System.out.print(x++);
      for(k=0;k<y;k++)
      System.out.print(" ");
      x--;
      for(j=0;j<m;j++)
      System.out.print(x--);
      System.out.println();
      if(i<9/2)
      {
      m--;
      }
      else
      {
      m++;
      }
      }
      }
      }

      Delete
  152. 1234554321
    1234---4321
    123------321
    12---------21
    1------------1
    12---------21
    123------321
    1234---4321
    1234554321
    "-" this is for space

    ReplyDelete
    Replies
    1. Already posted, still posting for the second time

      import java.io.*;
      class Arr
      {
      int i,j,x,y=0,k,m,n;
      public void show()
      {
      m=5;
      for (i=0;i<9;i++)
      {
      x=1;
      for(j=0;j<m;j++)
      System.out.print(x++);
      for(k=0;k<y;k++)
      System.out.print(" ");
      x--;
      for(j=0;j<m;j++)
      System.out.print(x--);
      System.out.println();
      if(i<9/2)
      {
      m--;
      y=y+3;
      }
      else
      {
      m++;
      y=y-3;
      }
      }
      }
      }

      Delete
  153. 1234554321
    1234---4321
    123------321
    12---------21
    1------------1
    12---------21
    123------321
    1234---4321
    1234554321

    ReplyDelete
  154. import java.io.*;
    class Arr
    {
    int i,j,x,y=0,k,m,n;
    public void show()
    {
    m=5;
    for (i=0;i<9;i++)
    {
    x=1;
    for(j=0;j<m;j++)
    System.out.print(x++);
    for(k=0;k<y;k++)
    System.out.print(" ");
    x--;
    for(j=0;j<m;j++)
    System.out.print(x--);
    System.out.println();
    if(i<9/2)
    {
    m--;
    y=y+3;
    }
    else
    {
    m++;
    y=y-3;
    }
    }
    }
    }

    ReplyDelete
  155. *****
    * *
    * *
    * *
    *****
    cn u tell me the java code abt this pattern.

    ReplyDelete
    Replies
    1. class border
      {
      int i,j,x=6;
      public void show()
      {
      for(i=0;i<5;i++)
      {
      for(j=0;j<x;j++)
      {
      if(x==3 && j%2==0)
      System.out.print("*");
      else if(x==3 && j%2!=0)
      System.out.print(" ");
      else
      System.out.print("*");
      }
      System.out.println();
      if(i==3)
      x=6;
      else
      x=3;

      }
      }
      }

      Delete
  156. sir can you Plzz solve

    -----*
    ----***
    ---*****
    --*******
    -*********
    ***********

    ReplyDelete
  157. class border
    {
    int i,j,k,x=1;
    public void show()
    {
    for(i=0;i<6;i++)
    {
    for(j=i;j<5;j++)
    System.out.print(" ");
    for(k=0;k<x;k++)
    System.out.print("*");
    System.out.println();
    x=x+2;
    }
    }
    }

    ReplyDelete
  158. class Arr
    {
    int i,j,x;
    String str="BLUEJ";
    public void show()
    {
    x=str.length();
    for (i=0;i<x;i++)
    {
    for(j=0;j<=i;j++)
    System.out.print(str.charAt(j));
    System.out.println();
    }
    }
    }

    ReplyDelete
  159. sir all of ur posts have been a great help to me thank u soooo much.sir i kindly request u to post the logic for the following pattern
    1234321
    23432
    343
    4
    343
    23432
    1234321
    sir i request u 2 post this as soon as possible.thank u.

    ReplyDelete
    Replies
    1. Please check my today's post

      Delete
    2. sir this is chaitanya itself no time to sign up since my internet connec is slow.respected sir i could not find your yesterday's post.plz tel me hw i can find it,sorry coz i'm new 2 ur site.

      Delete
    3. I think I have done some mistake. Ok, I am again posting the program:


      class Arr
      {
      int i,j,x,a=0,y=7;
      public void show()
      {
      for(i=0;i<7;i++)
      {
      if(i<=7/2)
      a++;
      else
      a--;
      x=a;
      for(j=0;j<y;j++)
      {
      if(j<y/2)
      System.out.print(x++);
      else
      System.out.print(x--);
      }
      if(i<7/2)
      y=y-2;
      else
      y=y+2;
      System.out.println();
      }
      }
      }

      Delete
    4. sir can you also post the code for the following
      *___________*
      ___*_______*_
      _____*___*_
      _______*____
      _____*___*__
      ___*_______*
      *____________*
      sir,plz give a bit of explanation since i just donot have any idea abt the program.

      Delete
  160. 1
    23
    456
    78910
    1112131415
    please sir..

    ReplyDelete
    Replies
    1. class A
      {
      int i,j,x=1;
      void show()
      {
      for(i=0;i<5;i++)
      {
      for(j=0;j<=i;j++)
      {
      System.out.print(x++);
      }
      System.out.println();
      }
      }
      }

      Delete
  161. a program for this pattern plz
    123456789
    2345678
    34567
    456
    5
    456
    34567
    2345678
    123456789

    ReplyDelete
  162. how to print that the no. entered is ARMSTRONG NUMBER or not..plzz tell fast Sir..

    ReplyDelete
    Replies
    1. Search in by blog, you will get the program.

      Delete
  163. I want this bluej program for the following pattern -

    a
    a b
    a b c
    a b c d

    ReplyDelete
    Replies
    1. import java.io.*;
      class Pattern
      {
      int i,j;
      char ch;
      void show()
      {

      for(i=0;i<4;i++)
      {
      ch='a';
      for(j=0;j<=i;j++)
      {
      System.out.print(ch+" ");
      ch=(char)(ch+1);
      }
      System.out.println();
      }
      }
      public static void main(String args[])
      {
      Pattern ob=new Pattern();
      ob.show();
      }
      }

      Delete
  164. I want bluej program for the following pattern -

    ---a
    --a b
    -a b c
    a b c d

    these - are blank spaces to be left , you need not to print these -s.

    ReplyDelete
    Replies
    1. class Merging
      {
      void show()
      {
      int i,j,k,x=1;
      char ch;
      for(i=0;i<4;i++)
      {
      ch='a';
      for(k=i;k<3;k++)
      System.out.print(" ");
      for(j=0;j<x;j++)
      {
      if(j%2==0)
      {
      System.out.print(ch);
      ch=(char)(ch+1);
      }
      else
      System.out.print(" ");

      }
      x=x+2;
      System.out.println();
      }
      }
      }

      Delete
  165. wap to find the sum of all the elements which lie on either diagonal.

    ReplyDelete
  166. wap to print pattern
    *
    **
    ***
    ****
    *****

    ReplyDelete
    Replies
    1. class Merging
      {
      void show()
      {
      int i,j;
      for(i=0;i<5;i++)
      {
      for(j=0;j<=i;j++)
      {
      System.out.print("*");
      }
      System.out.println();
      }
      }
      }

      Delete
  167. i know its not pattern but please do it.

    * wap to input a string and print out the text with the upper case and lower case letters reversed but all the characters should remain the same as before.
    eg;-Welcome TO School
    wELCOME to sCHOOL
    please do it many people want this program.

    ReplyDelete
    Replies
    1. class Pattern
      {
      void show(String str)
      {
      int i,len;
      len=str.length();
      for(i=0;i=65 && str.charAt(i)<=97)
      System.out.print((char)(str.charAt(i)+32));
      else if(str.charAt(i)>=97 && str.charAt(i)<=122)
      System.out.print((char)(str.charAt(i)-32));
      else
      System.out.print(str.charAt(i));
      }
      }
      }

      Delete
  168. do this one

    ----a
    ---a b
    --a b c
    -a b c d

    ReplyDelete
    Replies
    1. class Pattern
      {
      void show()
      {
      int i,j,k;
      char ch;
      for(i=0;i<4;i++)
      {
      ch='a';
      for(j=i;j<4;j++)
      System.out.print(" ");
      for(k=0;k<=i;k++)
      {
      System.out.print(ch+" ");
      ch=(char)(ch+1);
      }
      System.out.println();
      }
      }
      }

      Delete
  169. how to print pattern
    54321
    5432
    543
    54
    5

    ReplyDelete
    Replies
    1. class Pattern
      {
      void show()
      {
      int i,j,x;
      for(i=0;i<5;i++)
      {
      x=5;
      for(j=i;j<5;j++)
      {
      System.out.print(x--);
      }
      System.out.println();
      }
      }
      public static void main(String args[])throws Exception
      {
      Pattern ob=new Pattern();
      ob.show();
      }
      }

      Delete
    2. plz sir solve this question
      1 2 3 4 5
      1 2 3 4
      1 2 3
      1 2
      1

      Delete
  170. * * * * *
    * *
    * *
    * *
    * * * * *
    how would I print this one?
    thanks

    ReplyDelete
  171. can you please solve

    *
    ***
    *****

    but the triangle has a variable N, and N is the number of stars at the bottom line.
    You can assume that N will always be an odd number with a minimum value of 3.
    for example
    N=3
    *
    ***
    N=5
    *
    ***
    *****
    N=7
    *
    ***
    *****
    *******

    ReplyDelete
    Replies
    1. class Pat
      {
      int i,j,x=1;
      public void show(int n)
      {
      for(i=0;i<n;i++)
      {
      for(j=0;j<x;j++)
      {
      System.out.print("*");
      }
      x=x+2;
      System.out.println();
      }
      }
      }

      Delete
    2. class Pat
      {
      int i,j,x=1;
      public void show()
      {
      for(i=0;i<3;i++)
      {
      for(j=0;j<x;j++)
      {
      System.out.print("*");
      }
      x=x+2;
      System.out.println();
      }
      }
      }

      Delete
  172. please sir solve a question
    1 2 3 4 5
    1 2 3 4
    1 2 3
    1 2
    1

    ReplyDelete
  173. wap to print -
    123456789
    12345678
    1234567
    123456
    12345
    1234
    123
    12
    1

    ReplyDelete
    Replies
    1. class Pat
      {
      int i,j,x;
      public void show(int n)
      {
      for(i=0;i<n;i++)
      {
      x=1;
      for(j=i;j<n;j++)
      {
      System.out.print(x++);
      }
      System.out.println();
      }
      }
      }

      Delete
  174. Sir, please help me out with the following pattern program..... urgent..

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

    ReplyDelete

Subscribe via email

Enter your email address:

Delivered by FeedBurner