Creating Number Patterns In Java

Creating Number Patterns In Java

Number Pattern in Java
Creating number or symbol patterns is used to check command of a programmer or a student on for loop. In short its done just for practicing for loop.


Here are some common number patterns :

Pattern 1. 
Pattern 1
To Print this pattern use the following code:

public class numPtr {
    public static void main( String arg[]){
        for(int i=1;i<=5;i++){

            for(int j=1;j<=i;j++){
                System.out.print(j);
            }
            System.out.println();
        }
    }
}

Pattern 2. 
Pattern 2
To Print this pattern use the following code:

public class numPtr {
    public static void main( String arg[]){
            for(int i=1;i<=5;i++){
            for(int j=5;j>=i;j--){
                System.out.print(j);
            }
            System.out.println();
        }
    }
}

Pattern 3. 
Pattern 3
To Print this pattern use the following code:
public class numPtr {
    public static void main( String arg[]){
           for(int i=1,r=5;i<=5;i++,r--){
            for(int j=1;j<=r;j++){
                System.out.print(j);
            }
            System.out.println();        }
    }
}

Pattern 4. 
Pattern 4
To Print this pattern use the following code:
public class numPtr {
    public static void main( String arg[]){
int ck=0,c=2;
        while(c>0){
        if(ck==0){
            for(int i=1;i<=5;i++){
            for(int j=1;j<=i;j++){
                System.out.print(j);
            }
            System.out.println();         }
            ck++;
       } else{
            for(int i=1,r=5-1;i<=5-1;i++,r--){
            for(int j=1;j<=r;j++){
                System.out.print(j);            }
            System.out.println();
        }
        }
        c--;
      }

    }
}

Pattern 5. 

Pattern 5
To Print this pattern use the following code:
public class numPtr {
    public static void main( String arg[]){
int ck=0,c=2;
        while(c>0){
        if(ck==0){
            for(int i=1,r=5;i<=5;i++,r--){
            for(int j=1;j<=r;j++){
                System.out.print(j);
            }
            System.out.println();        }
            ck++;
       } else{
            for(int i=2;i<=5;i++){
            for(int j=1;j<=i;j++){
                System.out.print(j);            }
            System.out.println();
        }
        }
        c--;
      }

    }
}
Author Note: All the above examples gives output till 5, you can change it accordingly by changing the conditions. 

1065 Comments Leave new

«Oldest   ‹Older   1 – 200 of 1065   Newer›   Newest»

what will be the code for madam
D
A D A
M A D A M
M A D A D A M
M A D A M A D A M
M A D A D A M
M A D A M
A D A
D

Reply

Hello Koushik Kundu, Thanks for visiting!
Here's the code for the program you mentioned :


public class madamCODE {
public static void main( String arg[]){
/*****Ptinting The Upper Part*****/
for(int i=1;i < 10;i+=2){
System.out.println( print(i) );
}
/*****Ptinting The Lower Part*****/
for(int i=7;i > 0;i-=2){
System.out.println( print(i) );
}
}

public static String print(int n){
String term = "" , s[] = {"M","A","D"};
if(n==1){
term = "3,";
} else if(n==3){
term = "2,3,2,";
} else if(n==5){
term = "1,2,3,2,1,";
} else if(n==7){
term = "1,2,3,2,3,2,1,";
} else{
term = "1,2,3,2,3,2,3,2,1,";
}
String nums[] = term.split(",") , output="";
for(int j=0;j < nums.length;j++){
int at = Integer.parseInt(nums[j].toString())-1;
output = output + s[at]+" ";
}
return output;
}
}


Hope it will be helpful for you. If you don't understand anything, reply us and we'll get back to you as soon as possible!

Reply

what will be the code for
12345
2345
345
45
5

Reply

If you want to align all the numbers towards right!
Source Code :

public class comment {
public static void main( String arg[]){
for(int i=1 ; i<=5 ; i++){
for(int k=5-i ; k<4 ; k++){
System.out.print(" ");
}
for(int j=i ; j<=5 ; j++){
System.out.print(j);
}
System.out.println();
}
}
}

We hope you got your answer!
Keep visiting us, if you have any query or problem just leave your reply and we'll get back to you.

Reply

Can u pls help me in printing following pattern
if input=4

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

Reply

in above output there must be space between each number
ND in 2nd row 2 spaces before starting,
in 3 rd row 3 spaces like upto 1.

Reply

Hello Nitin Kumar!

Here's the solution:

public class comment {
public static void main( String arg[]){
int input = 4; //change it accordingly

for(int i=1 ; i<=input ; i++){
for(int j=1 ; j<=input-i+1 ; j++){
System.out.print(input-i+1+" ");
}
System.out.println();
}
for(int k=input-1; k>0 ; k--){
for(int l=2 ; l<=input-k+2 ; l++){
System.out.print(input-k+1+" ");
}
System.out.println();
}
}
}

Reply

Hello Nitin Kumar!
please be specific for the out!
do you want to print it like :
4 4 4 4
3 3 3
2 2
1
2 2
3 3 3
4 4 4 4

?? if yes , reply us back or print the correct output and we will get back to your reply.

Reply

What will be the code to print the following pattern...
1
2 3
4 5 6
7 8 9 10

Reply

Hello Harish Raghav!
Here's what you need:

public class comment {
public static void main( String arg[]){
int rows = 4; //change rows accordingly
int cout = 1;
for(int i=1;i<=rows;i++){
for(int j=0;j<i;j++){
System.out.print(cout+" ");
cout++;
}
System.out.println();
}
}
}

Reply

what will be the output of below pattern
enter a number example 6
the pattern is 1 1 1 1 1 2
3 2 2 2 2 2
3 3 3 3 3 4
and so on

Reply

Here's the code:
public class series {
public static void main (String args[]){
int in = 6; //change input
for(int i=1;i<=in;i++){
for(int j=1;j<in;j++){
System.out.print(i);
if(j==in-1){
System.out.println(i+1);
}
}
}
}
}

If you need any further assistance fell free to contact us!

Reply

Code for
1
12
12
123
1234
1234
1234
12345
123456
123456
123456
123456
1234567
12345678
12345678
12345678

Reply

Hello Dheeraj S!
Here's your program:

public class numberpattern {
public static void main(String args[]){
int i=1; //Change this value
for(;i<9;i++){
int test=1;
for(int j=1;j<=i;j++){
if(i%2==0){
System.out.print(j);
if(j==i && test<=i/2){
j=0;
test++;
System.out.println();
continue;
}
} else{
System.out.print(j);
}
}
System.out.println();
}
}
}

For further assistance feel free to contact us!

Reply

Help me with this
*1
*23
*456
*78910
*111213

Reply

Here's the Code:
public class numberpattern {
public static void main(String args[]){
int j=1;
for(int i=1;i<=5;i++){
System.out.print("*");
for(int k=0;k<i && j<=13;k++){
System.out.print(j);
j++;
}
System.out.println();
}
}
}

Reply

hello...

this program is working for in=6 only...but y nt for 3,4,5 nd so on

Reply

Hello Richa Saxena!
I checked this program again and its working for all the numbers.
I think you want any other output, Reply your desired output and it will be correct accordingly.

Reply

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

plz get me the code for this

Reply

Hello Vivek!
Here's the CODE:

public class series {
public static void main (String args[]){
int ln = 5; //change number of lines
int out = 1;
for(int i=1;i<=ln;i++){
String outline = "";
if(i%2==0){
int out1 = out + i - 1;
for(int j=0;j<i;j++){
outline = outline + out1;
out1--;
if(j!=i-1){
outline = outline + "*";
} else{
out = out+j+1;
}
}
} else{
for(int j=0;j<i;j++){
outline = outline + out;
out++;
if(j!=i-1){
outline = outline + "*";
}
}
}
System.out.println(outline);
}

}
}

Reply

plz tell me how to print the pattern as follows
1 2 3
4 5 6
7 8 9

Reply

Hello Sanjay! Thanks for commenting, here is the code you want:

public class pattern{
public static void main(String []args){
for(int i=1;i<=9;i++){
for(int j=0;j<3;j++){
System.out.print(""+i);
i++;
}
i--;
System.out.println();
}
}
}

Reply

How to do this pattern.........? please reply fast
1234554321
1234 4321
123 321
12 21
1 1

Reply

Hello Mrinal kumar! as per your request we are replying to your question as fast as possible :) (in 15 min.)
Code for your problem:

public class series {
public static void main (String args[]){

for(int i=1,r=5;i<=5;i++,r--){
for(int j=1;j<=r;j++){
System.out.print(j);
}
if(r!=5){System.out.print(" ");}
for(int k=r;k>=1;k--){
System.out.print(k);
}
System.out.println(); }
}
}

feel free to reply if you have any other problem!

Reply

sir can you please give the code for the following pattern
5432112345
4321 1234
321 123
21 12
1 1

Reply

Hello Kamal, thanks for visiting Code Nirvana.
Solution to your problem:

public class series {
public static void main (String args[]){

for(int i=1;i<=5;i++){
for(int j=6-i;j>=1;j--){
System.out.print(j);
}
if(i>1){System.out.print(" ");}
for(int k=1;k<=6-i;k++){
System.out.print(k);
}
System.out.println();
}
}
}

Reply

Thank you sir for fast reply its very much helpful. can you please give the coding for

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

Reply

Thank you sir for fast reply its very much helpful. can you please give the coding for

5 4 3 2 1
-- 5 4 3 2
------5 4 3
---------5 4
------------5
---------5 4
------5 4 3
---5 4 3 2
5 4 3 2 1

Reply

Welcome back Kamal, and glad to see you liked our responsibility regarding replying to our visitors.
Solution for:
5 4 3 2 1
5 4 3 2
5 4 3
5 4
5
5 4
5 4 3
5 4 3 2
5 4 3 2 1

Source Code:

public class series {
public static void main (String args[]){

for(int i=1;i<=5;i++){
for(int j=5;j>=i;j--){
System.out.print(j);
}
System.out.println();
}
for(int i=1;i<5;i++){
for(int j=5;j>4-i;j--){
System.out.print(j);
}
System.out.println();
}
}
}

Reply

sir can you give the coding for
1
2 1
3 2 1
4 3 2 1
5 4 3 2 1

Reply

5 4 3 2 1
-- 5 4 3 2
------5 4 3
---------5 4
------------5
---------5 4
------5 4 3
---5 4 3 2
5 4 3 2 1

sir when i tried this program it did not compile it had a error

Reply

[UPDATED] Solution for:
54321
-5432
--543
---54
----5
---54
--543
-5432
54321

Source Code:

public class series {
public static void main (String args[]){

for(int i=1;i<=5;i++){
//spacing logic
for(int s=1; s < i; s++){
System.out.print("-");
}
//main logic: loop1
for(int j=5 ; j >= i; j--){
System.out.print(j);
}
System.out.println();
}
for(int i=1;i<5;i++){
//spacing logic
for(int s=4;s>i;s--){
System.out.print("-");
}
//main logic: loop2
for(int j=5;j>4-i;j--){
System.out.print(j);
}
System.out.println();
}
}
}

P.S- Bug Noticed by ' Rasswanth Rick ' Thank you friend!

Reply

Hello Rasswanth!
thank you for pointing out a bug in our code. Above comment is updated and you can check it now.

Reply

@Rasswanth code for your pattern is:

public class series {
public static void main (String args[]){
for(int i=1;i<=5;i++){
for(int j=i;j>=1;j--){
System.out.print(j);
}
System.out.println();
}
}
}

Reply

thank you for helping with the bug sir,but sir the result i am expecting should not come with a method call.
sir i am very much happy with your result for my program please would be kind to give this coding also
-------- 1
------2 1 2
--- 3 2 1 2 3
--4 3 2 1 2 3 4
5 4 3 2 1 2 3 4 5
-- 4 3 2 1 2 3 4
- --- 3 2 1 2 3
- - ---- 2 1 2
-- -- ---- 1


Reply

can any one tell me the code for S shape

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

Reply

Hello RIYAZ, asking for a interesting pattern! so, code to print ' S ' pattern is:

public class series {
 public static void main (String args[]){
  int len = 5; //change this length accordingly
  for(int i=1;i<=3;i++){
   for(int j=1;j<=len;j++){
    System.out.print('*');
  }
   System.out.println();
   if(i==3){
    break;
   } else if(i%2==0){
    for(int s=1;s<len;s++){
     System.out.print(" ");
     if(s==len-1){System.out.println('*');}
     }
    } else{
    System.out.println('*');
   }
  }
 }
}

Reply

Thank you for commenting again! we love to solve problems of our visitors and we will defiantly solve this problem too... try the code given below!

public class series {
    public static void main ( String arg[] ){
            int num = 5;
            //upper triangle
            for(int i=1;i<=num;i++){
                for(int j=1;j < num-(i-1);j++){
                    System.out.print("-");
                }
                for(int k=i;k>=1;k--){
                    System.out.print(k);
                }
                for(int k1=2;k1<=i;k1++){
                        System.out.print(k1);
                    }
                System.out.println();
            }
            //lower triangle    
            for(int i=1;i<=num-1;i++){
                for(int j=i;j>=1;j--){
                    System.out.print("-");
                }
                for(int k=num-i;k>=1;k--){
                    System.out.print(k);
                    
                }
                for(int k1=2;k1<=num-i;k1++){
                        System.out.print(k1);
                    }
                System.out.println();     
            }
    }
}

Note: You might also like: Triangle Patterns Programs

Reply

Pls let me know the code for the following pattern..
11111
10001
10001
10001
11111

Reply

Hello Nishita!
Check this Code:

public class series {
    public static void main ( String arg[] ){
            int num = 5;    //change accordingly
            for(int i=1;i<=num;i++){
                if(i==1 || i==num){
                    for(int j=1;j<=num;j++){
                        System.out.print("1");
                    }
                } else{
                    for(int j=1;j<=num;j++){
                        if(j==1 || j==num){
                            System.out.print("1");
                        } else{
                            System.out.print("0");
                        }
                    }
                }
                System.out.println();
            }
    }
}

Reply

Pls let me know the code for the following pattern.
1
2*2
3*3*3
4*4*4*4
4*4*4*4
3*3*3
2*2
1

Reply

Hi Shubhangi, Code for the pattern you asked:

public class series {
    public static void main ( String arg[] ){
            int num = 4;    //change this value
            //Upper triangle
            for(int i=1;i<=num;i++){
                for(int j=1;j<=i;j++){
                    if(j!=1){
                        System.out.print("*"+i);
                    } else{
                        System.out.print(i);
                    }
                }
                System.out.println();
            }
            //Lower triangle
            for(int i=num;i>=1;i--){
                for(int j=1;j<=i;j++){
                    if(j!=1){
                        System.out.print("*"+i);
                    } else{
                        System.out.print(i);
                    }
                }
                System.out.println();
            }
    }
}

Reply

can u plz help me with:
55555
54444
54333
54322
54321

Reply

Hi Samia, thanks for asking such a great pattern.
Source Code:
public class series {
    public static void main (String args[]){
        int in = 5; //change input
        for(int i=1;i<=in;i++){
            for(int a=in;a > in+1-i && i!=1;a--){
                System.out.print(a);
            }
            for(int j=in;j>=i;j--){
                System.out.print(in+1-i);
            }
            System.out.println();
        }
    }
}

Reply

hi admin
can u give me the code for the following pattern
****
**
****
*

Reply

Hello Shivani
Source Code:

public class series {
    public static void main (String args[]){
        int in = 3; //change input
        for(int i=1;i < in;i++){
            for(int j=1;j<=in;j++){
                System.out.print("*");
            }
            System.out.println();
            for(int k=1;k<=in-i;k++){
                System.out.print("*");
            }
            System.out.println();
        }
    }
}

Reply

thank you soo much
can u get me the code for the following patterns please
1
2 3
4 5 6
7 8 9 10
and the other pattern is
7 8 9 10
4 5 6
2 3
1

Reply

Pattern:
1
2 3
4 5 6
7 8 9 10

Code:
public class series {
    public static void main (String args[]){
        int ln = 4; //Number Of Lines
        for(int i=1,print=1;i <=ln;i++){
            for(int j=1;j<=i;j++){
                System.out.print(print);
                print++;
            }
            System.out.println();
        }
    }
}

Reply

Pattern:
7 8 9 10
4 5 6
2 3
1

This pattern is a great pattern, nice logic! Check the solution given below and let us know if you want any other help!

Code:
public class series {
    public static void main (String args[]){
        int ln = 4; //Number Of Lines
        //Calculate maximum number of series
        int num=0;
        //for EVEN value of var. ln
        if(ln%2==0){
            num = ln*(ln/2)+(ln/2);
        }
        //for ODD value of var. ln
        else{
            num = ln*(ln/2)+ln;
        }
        for(int i=1,temp=num-ln+1; i<=ln; i++,temp=temp-ln+i-1){
            int print = temp;
            for(int j=ln; j>=i; j--){
                System.out.print(print+" ");
                print++;
            }
            System.out.println();
        }
    }
}

Reply

1
11
112
1123
11235
112358

....plz sove this pattern

Reply

Hello Tushar!
liked your pattern logic. Sorry for the late reply, I tried to solve your problem asap.. so the logic used might look strange to you :) but its working perfectly!

Source Code:

public class series {
    public static void main (String args[]){
        int ln = 6; //Number Of Lines
        int pre1 = 1 , pre2 =0; 
        String temp = "";
        System.out.println(1);
        for(int r=1;r < ln;r++){
            System.out.print(1);
            for(int c=1;c<=r;c++){
                int print = 0;
                if(temp.length() >= c ){
                    System.out.print(temp.subSequence(c-1, c));
                } else{
                    print = pre1+pre2;
                    System.out.print(print);
                    pre1 = pre1+pre2 +pre1- (pre2 = pre1);
                    temp = temp + print;
                }
            }
            System.out.println();
        }
    }
}

If you have any other problem related to this program or any other program than let us know!

Reply

What will be the code for the following
1 3 5 7 9
3 5 7 9 1
5 7 8 1 3
7 9 1 3 5
9 1 3 5 7

Reply

Hello Earnest!
I tried the string substitution logic using substring. Check it out!
Code:
public class series {
    public static void main (String args[]){
        int ln = 5; //Number Of Lines
        String nums = "";
        for(int i=1, o=1;i<=ln;i++,o+=2){
            nums = nums + o;
        }
        for(int j=1;j<=ln;j++){
            System.out.println(nums);
            nums = nums.substring(1,ln) + nums.substring(0,1);
        }
    }
}

Reply

Hi,
can you please write code for this pattern.
---------------------------------------1
-------------------------------------1 1
-----------------------------------1 3 3 1
----------------------------------1 4 6 4 1
-------------------------------1 5 10 10 5 1

Reply

@Bodybuilding
The pattern you asking for is known as Pascals Triangle.
for the source code please visit here- Pascals Triangle In Java

Reply

@venkateshbc
The pattern you are asking for is the very first pattern of this post!
So, kindly see the first example code of this post.

Reply

hi
can u plz write ur code for this pattern

1
22
333
4444
55555
4444
333
22
1

Reply

Hello Shashank!
Code:
public class series{
    public static void main(String args[]) {
        int n = 5;           // max number
        for(int i=1; i< n*2;i++){
            if(i <= n){
                for(int j=1;j<=i;j++){
                    System.out.print(i);
                }
                if(i==5){ System.out.println(); continue;}
            } else{
                for(int j=n-1;j>=i-n;j--){
                    System.out.print(n*2-i);
                }
            }
            System.out.println();
        }
    }
}

Reply

sir will you will please give the codin gfor this pattern as soon as possible
a
abc
abcde
abcdefg
abcdefghi
abcdefghijk

Reply

Hello Preeti... I hope its asap :)
Source Code:
public class series{
    public static void main(String args[]) {
        String txt = "abcdefghijk";
        for(int i=1; i<=txt.length(); i+=2){
            for(int j=1,s=0; j<=i; j++){
                System.out.print(txt.substring(s, s+1));
                s++;
            }
            System.out.println();
        }
    }
}

Reply

thank u sir for giving this code i really need this code thanks again

Reply

1
1 2 1
1 2 3 2 1
1 2 3 4 3 2 1
may i know the code of this pattern
plzzzzzzzz

Reply

Hi Shalini Dubey, code to print the pattern as you mentioned is...

Code:
public class series{
    public static void main(String args[]) {
        int num = 4;    //Max. No. In Series
        for(int i=1; i<=num; i++){
            for(int j=1;j<=i;j++){
                System.out.print(j+" ");
            }
            for(int k=i-1;k>=1;k--){
                System.out.print(k+" ");
            }
            System.out.println();
        }
    }
}

Reply

plzzzz tell me code of this pattern
.................................................1
..............................................1 2 1
...........................................1 2 3 2 1
........................................1 2 3 4 3 2 1
......................................1 2 3 4 5 4 3 2 1

Reply

Ok! so you want to align all these to center...
Code:
public class series{
    public static void main(String args[]) {
        int num = 4;    //Max. No. In Series
        for(int i=1; i<=num; i++){
            //Spacing Logic
            for(int s=i;s<=num;s++){
                System.out.print("  ");
            }
            for(int j=1;j<=i;j++){
                System.out.print(j+" ");
            }
            for(int k=i-1;k>=1;k--){
                System.out.print(k+" ");
            }
            System.out.println();
        }
    }
}

Reply

plzzzz tell me method pf this pattern plzzzzzzz
.......................................................................1
....................................................................2 3 2
.................................................................3 4 5 4 3
..............................................................4 5 6 7 6 5 4

Reply

Welcome back with your new question! :)

Code:
public class series{
    public static void main(String args[]) {
        int ln = 4;    //Number of lines/rows
        for(int i=1; i<=ln; i++){
            //Spacing Logic
            for(int s=i;s<=ln;s++){
                System.out.print("  ");
            }
            for(int j=1,p=i;j<=i;j++,p++){
                System.out.print(p+" ");
                if(j==i){
                    p--;
                    for(int k=1;k<i;k++,--p){
                        System.out.print(p+" ");
                    }
                }
            }
            System.out.println();
        }
    }
}

Keep visiting and let us know if you have any other problem/question related to programming...

Reply

*
***
*****
*******
*********
sir i want the coding of this pattern

Reply

s
se
sec
sect
secto
sector
plz send coding for all this

Reply

Hello Preeti, thank you for contacting us again...
code for this pattern is much easier than the one you asked earlier!
Code:
public class series{
    public static void main(String args[]) {
        String txt = "sector";    //Text/Paragraph to print
        for(int i=1; i<=txt.length(); i++){
            System.out.println(txt.substring(0, i));
        }
    }
}

Reply

*
**
***
****
Sir i want the coding of this pattern

Reply

what is code for following patren...??
input:amit is a good boy
a i a g b
m s * o o
i * * o y
t * * d *

Reply

Hello Amit Sachdeva!
I suggest you to please visit our previous post: Program to Print Triangle Pattern in java
Because the pattern you are looking for is already explained there.
Still if you have any other problem, feel free to contact us!

Reply

Hi Visheshta Singh!
Its not a basic number or string pattern, its a advance problem to test logic...
Thanks for asking this awesome question, really interesting question to check problem solving ability :)

Source Code:
public class series{
    public static void main(String args[]) {
        String txt = "amit is a good boy ";  //Text/Paragraph to print
        String arr[] = txt.split(" ");      //Make array of given txt
        //find string with max length
        int ln = 0;
        for(int i=0;i < arr.length;i++){
            String temp = arr[i];
            if(temp.length()>ln) ln = temp.length();
        }
        //arrange the words
        txt = "";   //clear previous text for reuse
        for(int j=0;j < arr.length;j++){
            String temp = arr[j];
            if(temp.length()<ln){
                for(int x=0;temp.length()<ln;x++){
                    temp = temp + "*";
                }
            }
            txt = txt + temp;
        }
        //finally print the output
        for(int p=0;p < ln;p++){
            for(int q=0,point = p;q < arr.length;q++,point+=ln){
                System.out.print(txt.substring(point, point+1));
            }
            System.out.println();
        }
    }
}

Reply

how to print this
1
3 1
5 3 1
7 5 3 1
9 7 5 3 1
Please help me out..:D

Reply

@Writer$Helper
Welcome to Code Nirvana, we will surely help you out :)

Code:
public class series{
    public static void main(String args[]) {
        int ln = 5; //Number of lines
        for(int i=1,odd=1;i<=ln;i++,odd+=2){
            for(int j=0;j < i;j++){
                System.out.print(odd-j*2+" ");
            }
            System.out.println();
        }
    }
}

Reply

please make changes to this program acc. to this
1
10
101
1010
10101

prog.:-
class iter16
{
public static void main(String Args[])
{
int l=1;
for(int i=0;i<5;i++)
{
for(int j=i+1;j>0;j--)
{
System.out.print(l);
l-=1;
System.out.print(l);
l+=1;
}
System.out.println();
}
}
}

o/p:-
10
1010
101010
10101010
1010101010

Reply

Hello again!
Hope your previous question was solved perfectly :)
For this pattern program I changed all your code to make it short, easier and understandable... added comments too for better understanding, run this code and let us know is it working for you!

Code:
class iter16 {
    public static void main(String Args[]) {
        for(int i=0;i < 5;i++) {       //for printing 5(default) lines
            int l = 1;               //Always starting with 1
            for(int j=0;j<=i;j++) {  //for printing colums acc. to line
              System.out.print(l);   //print var l
              l = (l==1) ? 0 : 1;    //Change var. l to 1 or 0 using ? : opt.
            }
            System.out.println();    //New line
        }
    }
}

Reply

please help with the code for
55555
54444
53333
52222
51111

Reply

hi codenirvana! please help me with this java program, its in nested loop with 2 loops:
1
121
12321
1234321
123454321
1234321
12321
121
1
thank you in advance!

Reply

Hi Shubham!
Code for this pattern is given below! and It looks like you deleted your other question for a pattern.... If you have any other question feel free to reply!
CODE:
class series {
    public static void main(String Args[]) {
        int max = 5;    //max no. in series
        //Upper Triangle
        for(int i=1;i<=max;i++){
            for(int j=1;j<=i;j++){
                System.out.print(j);
            }
            for(int k=i-1;k>=1;k--){
                System.out.print(k);
            }
            System.out.println();
        }
        //Lower Triangle
        for(int i=1;i<=max-1;i++){
            for(int j=1;j<=max-i;j++){
                System.out.print(j);
            }
            for(int k=max-i-1;k>=1;k--){
                System.out.print(k);
            }
            System.out.println();
        }
    }
}

Reply

Hello Rishab Tibrewal, for your patter here is you code...
Code:
class series {
    public static void main(String Args[]) {
        int max = 5;    //max no. of series
        for(int i=max;i>=1;i--){
            System.out.print(max);
            for(int j=1;j < max;j++){
                System.out.print(i);
            }
            System.out.println();
        }
    }
}

Reply

How to print
4444
4333
4322
4321
Your Help is Ever appreciated.

Reply

Hello Swapnil Parekh!
This same pattern we answered earlier too in this comments section ( at C-No. < 22 /> )
Still here's the same code you wanted...
Source Code:
public class series {
    public static void main (String args[]){
        int in = 4; //change input
        for(int i=1;i<=in;i++){
            for(int a=in;a > in+1-i && i!=1;a--){
                System.out.print(a);
            }
            for(int j=in;j>=i;j--){
                System.out.print(in+1-i);
            }
            System.out.println();
        }
    }
}

Reply

Hi!
Can you help me print the following series please:
1
121
12321
1234321
123454321

Reply

Hello, thanks for the series above but what about the Look and Say sequence?
1
11
21
1211
YOUR HELP IS APPRECIATED!!

Reply

Hello Trishita!
Same pattern we solved at CNo. < 43 />. I suggest you to do check that too....
for your pattern, viz. upper triangle of < 43 /> pattern!
Source Code:
class series {
    public static void main(String Args[]) {
        int max = 5;    //max no. in series
        for(int i=1;i<=max;i++){
            for(int j=1;j<=i;j++){
                System.out.print(j);
            }
            for(int k=i-1;k>=1;k--){
                System.out.print(k);
            }
            System.out.println();
        }
    }
}

Reply

Hello Again!
I think this pattern might be wrong because there's no systematic logic I found....
I request you to please print this pattern for at least 5 lines, to get the logic and solve your problem ASAP :)

Reply

Sir , I would like to know the way how to make patterns like
1
23
456
78910
11 12 13 14 15
Or
12345
22345
33345
44445
55555
I actually know the answers but I don't know how to make the patterns myself.
Can u plz guide me and tel me the tricks and tips to make any kind of pattern...
Waiting for ur reply.

Reply

can u help me with this
*1
*23
*456
*78910

Reply

Hello Kankana!
Same question was asked by Mithu Majumder earlier, check comment <10/>.
Still if you have any problem... feel free to contact us :)

Reply

Hello Rohan Baluja!
So as you already know the answers of these two patterns so i am skipping the first question and coming to the second question How to make these patterns.
So for these types of patterns....
1st you need to count the number of triangle or repetitive numeric patter present in the given pattern. Like for you first pattern there's just 1 triangle pattern with the logic of increment of numbers by one and starting from 1.
2nd create a for loop with the condition of number of lies or rows in your pattern!
Like: for(int i=1;i<=Lines;i++){ }
now create a nested for loop inside the above for loop with the condition satisfying the number of characters/numbers it will print in a row/line.
Like the 1st pattern needs output as number of columns in current row = number of that row means for 1st it print just 1 no. for 2nd it gives 2 no. and so on....
now finally you need a variable which you need to print with ++ after every execution!

Note: Practice is the only method to learn printing these patterns so i suggest you to check the comments asked by others above and check my answer to those questions and understand the logic.

Reply

Hi! Can u pls help me to print the following series in java??
5
45
345
2345
12345

All the 5s in 1 series, all the 4s in one, all the 3s in one and all d 2s in one...pls help me...

Reply

Hello Rimjhim Ghosh!
I think you want to align all the series towards right according to number....
So, for that try the code given below and do respond, is that's the code you're asking for in your last line :)
public class series{
    public static void main (String args[]){
        int n = 5;  //max num or lines
        int p = n;  //copy max value to p
        for(int i=1;i<=n;i++){      //Number of lines
            for(int s=n;s>i;s--){   //Align Numbers
                System.out.print(" ");
            }
            for(int j=1;j<=i;j++,p++){  //Printing
                System.out.print(p);
            }
            p = n - i;              //Set for the next run
            System.out.println();   //New Line
        }
    }
}

Reply

Hi Can you please Help me with this pattern ?
a=1,b=1,c=1. and the pattern is...
121
1331
14641
you can use any number of for loop with a,b,c values.
Thanks in advance...!

Reply

The pattern shown is also known as Pascal Triangle!
Visit : Pascals Triangle In Java
If still you have any question... feel free to reply!

Reply

code for following pattern
12345678910
1112131415617181920
so on up too 100

Reply

Hello Satyaveer, its a easy pattern.... check the code given below!
public class series{
    public static void main (String args[]){
        for(int i=1;i<=100;i+=10){
            for(int j=0;j < 10;j++){
                System.out.print(i+j);
            }
            System.out.println();
        }
    }
}

Reply

This is interview question I faces ..
how to get this pattern
***1***
**2*2**
*3*3*3*
4*4*4*4

Reply

i want like this typeof stars

*1*
**2**
***3***
****4****
*****5*****

Reply

Hello Sathish
check this code:
public class series{
    public static void main (String args[]){
        int num = 5; //change this accordingly
        for(int i=1;i<=num;i++){
            stars:
            for(int j=1;j<=i;j++){
               System.out.print("*");
            }
            System.out.print(i);
            for(int j=1;j<=i;j++){
               System.out.print("*");
            }
            System.out.println();
        }
    }
}

Reply

Sir,
please tell me what is java code to generate
1
01
101
0101
10101

Reply

Hi Shivling!
Nice pattern concept with 1 and 0, check the code below:
public class series{
    public static void main (String args[]){
        int ln = 5;    //change this accordingly
        int print = 0; //var. with value 0 & 1
        for(int i=1;i<=ln;i++){
            print = (i%2==0)?0:1;       //check for even-odd var. i
            for(int j=1;j<=i;j++){
                System.out.print(print);
                print = (print==0)?1:0; //change value-> 1 if 0 and 0 if 1
            }
            System.out.println();       //New line
        }
    }
}

Reply

Please help me in making this number pattern
33 32 31 30
23 22 21 20
13 12 11 10
03 02 01 00

Reply

Hello Ali!
We are sorry for the delay, your pattern is completely perfect there's no problem in this question... check the code given below:
public class series{
    public static void main (String args[]){
        int ln=4;    //change this accordingly
        for(int i=1;i<=ln;i++){
            stars(ln,i); //print stars
            for(int j=1;j<=i;j++){
                if(j < i) System.out.print(i+"*");
                else System.out.print(i);
            }
            stars(ln,i); //print stars
            System.out.println();
        }
    }
    //Star printing function
    static void stars(int ln,int i){
        for(int s=ln;s > i;s--){
            System.out.print("*");
        }
    }
}

Hope this code works perfectly for you, if there's any other problem, let us know!

Reply

Hello Mehak!
Run the code given below....
public class series{
    public static void main (String args[]){
        int ln=3;    //change this accordingly
        for(int i=0;i<=ln;i++){
            for(int j=0;j<=ln;j++){
                System.out.print(""+(ln-i)+(ln-j)+" ");
            }
            System.out.println();
        }
    }
}

Reply

Thank you so much sir. Kindly help me with this number pattern as well
00 00 00 00
00 11 00 00
00 00 22 00
00 00 00 33

Reply

Glad to know our code works perfectly for you!
for the above pattern only one line should be changed...
Use the same code and replace System.out.print(""+(ln-i)+(ln-j)+" ");
with:
if(j==i) System.out.print(""+i+i+" ");
else System.out.print("00 ");

Reply

Sir explain the concept of selection sort in java with an example

Reply

In selection sorting we have to find the minimum value in the array then swap its first position. In next step leave the first value and find the minimum value within remaining values. Then swap it with the value of minimum index position. Sort the remaining values by using same steps

Its just a little algorithm to do sorting! Very soon we will post complete articles on sorting and other important operations with arrays....
To get the regular updates subscribe to our free News Letter: Click Here

Reply

1
2 2
3 3 3
4 4 4 4
send code for this program

Reply

Ishankar sir here's you code :)

public class series{
    public static void main (String args[]){
        int ln=4;    //change this accordingly
        for(int i=1;i<=ln;i++){
            for(int j=1;j<=i;j++)
                System.out.print(i);
            System.out.println();
        }
    }
}

Reply

21 22
31 32
41 42
51 52
can u plz send the code for this pattern thanks

Reply

Hello Again!
Code for the above pattern is:
public class series{
    public static void main (String args[]){
        int p=2 , q=5;
        for(int i=p ; i<=q; i++){
            for(int j=1; j<=2;j++){
                System.out.print(""+i+j+" ");
            }
            System.out.println();
        }
    }
}

Reply

can u help for this

1
01
101
0101
10101

Reply

Hello Arnab!
The same pattern I answered at comment <55 /> .
Check that code...

Reply

can u please send me the pattern

for ex=90


1 3 9 27 81

1 3 9 27

1 3 9

1 3

1

Reply

Check this code:
public class series {
    public static void main ( String arg[] ){
        int ex = 90;
        int pre , i , j;
        for( i=1 ; ex>=1 ; i++ , ex/=3 ){
            pre = 1;
            for( j=1 ; j<=ex ; j=pre*3 ){
                System.out.print(j+" ");
                pre = j;
            }
            if(i==1)
                ex = j/3;
            System.out.println("\n");
        }
    }
}

Reply

Please help in solving this pattern

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

Reply

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

Reply

this is my problem,please help me as soon as possible
1
2 1
3 2 1
4 3 2 1
5 4 3 2 1
6 5 4 3 2 1
please give me answer as soon as possible,
my homework

Reply

Hello!
This pattern is solved at comment <16/ >.
So, scroll up and check that comment and our reply!

Reply
This comment has been removed by a blog administrator.

Please help me as soon as possible in solving this problems


COMPUTER
COMPUTE
COMPUT
COMPU
COMP
COM
CO
C



THNX....

Reply

Here it is:
public class series {
    public static void main ( String arg[] ){
        String text = "COMPUTER";
        int len = text.length();
        for(int i=0;i<len;i++){
            System.out.println( text.substring(0,len-i) );
        }
    }
}

Reply

CAN U HELP ME IN THIS

-----------a
---------bab
-------cbabc
-----dcbabcd
---edcbabcde

Reply

Check This Code:
public class series {
    public static void main ( String arg[] ){
        int ln =5;
        char c = 'a';
        for(int i=1;i<=ln;i++,c+=i){
            for(int s=ln;s>i;s--) System.out.print("-");
            for(int j=1;j<i*2;j++){
                if(j<=i){
                    System.out.print(c);
                    c--;
                } else {
                    char d = (char) (c+j-i+1);
                    System.out.print(d);
                    d++;
                }
            }
            System.out.println();
        }
    }
}

Reply

Please send me this code as fast as possible.


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

Reply

hello,
could you please tell me the code of this pattern:
5 5 5 5 5
4 4 4 4
3 3 3
2 2
1

Reply

hello can you help me printing this
1
212
32123
4321234
543212345
4321234
32123
212
1

Reply

Check this code for the above pattern:
public class series {
    public static void main ( String arg[] ){
        int ln=5;   //Number of lines/rows
        for(int i=0;i<ln;i++){
            for(int j=ln;j>i;j--){
                System.out.print(ln-i+" ");
            }
            System.out.println();
        }
    }
}

Reply

For the pattern you mentioned, check this code:
public class series {
    public static void main ( String arg[] ){
        int ln=5;
        //Upper Triangle
        for(int i=1;i<=ln;i++){
            for(int s=ln;s>i;s--) System.out.print(" ");
            for(int j=0;j<i;j++)  System.out.print(i-j);
            for(int j=2;j<=i;j++) System.out.print(j);
            System.out.println();
        }
        //Lower Triangle
        for(int i=1;i<ln;i++){
            for(int s=1;s<=i;s++)    System.out.print(" ");
            for(int j=ln-i;j>0;j--)  System.out.print(j);
            for(int j=2;j<=ln-i;j++) System.out.print(j);
            System.out.println();
        }
    }
}

Reply

PLEASE HELP IN PRINT THE FOLLOWING CODE :-


T
TE
TEA
TEAC
TEACH
TEACHE
TEACHER


&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&


TEACHER
--EACHER
----ACHER
------CHER
---------HER
-----------ER
-------------R




PLEASE SEND ME ABOVE CODE FASTAS SOON AS POSSIBLE.

THNX...........................................................................................

Reply

print this:

n=4

1 2 3 4 17 18 19 20
5 6 7 14 15 16
8 9 12 13
10 11

Reply

Awesome pattern logic!
Here's the solution:
class series{
    public static void main(String args[]){
        int n = 4;
        int p=1 , q=n*n+1   ,   r;
        for(int i=0;i<n;i++){
            r = q;  //Copy Value of q
            for(int j=1;j<=(n-i)*2;j++){
                if(j<=n-i){
                    System.out.print(p+" ");
                    p++;
                } else{
                    System.out.print(q+" ");
                    q++;
                }
            }
            System.out.println();   //New Line
            q = r = r - (n-i-1);    //Set Next Value Of q
        }
    }
}

Reply

Pattern 1 Code:
class series{
    public static void main(String args[]){
        String txt = "TEACHER";
        for(int i=1;i<=txt.length();i++){
            System.out.println(txt.substring(0, i));
        }
    }
}


and,

Pattern 2 Code:
class series{
    public static void main(String args[]){
        String txt = "TEACHER";
        for(int i=0;i<txt.length();i++){
            for(int s=i;s>0;s--)    System.out.print("-");
            System.out.println(txt.substring(i, txt.length()));
        }
    }
}

Reply

Can anyone send code for following pattern?
1
1 1
1 2 1
1 3 3 1
1 4 4 4 1
1 5 5 5 5 1

Reply

Thipparthi , code for above pattern is:
class series{
    public static void main(String args[]){
        int n=6;
        for(int i=1;i<=n;i++){
            for(int j=1;j<=i;j++){
                if(j==1 || j==i){
                    System.out.print(1+" ");
                } else{
                    System.out.print(i-1+" ");
                }
            }
            System.out.println();
        }
    }
}

Reply

how to print this code ?
5
44
333
2222
11111

Reply

For the above pattern... this is the code:
class series{
    public static void main(String args[]){
        int row = 5;
        for(int i=0;i<row;i++){
            for(int j=0;j<=i;j++){
                System.out.print(row-i);
            }
            System.out.println();
        }
    }
}

Reply

actually the pattern is as below.
*
* *
* * *
* *
*

Reply

Hello Gaurav Das, I think you want them in centre! right?
for that pattern... check this code:
class series{
    public static void main(String args[]){
        int row = 3;
        //upper triangle
        for(int i=1;i<=row;i++){
            for(int s=i;s<row;s++) System.out.print(" ");
            for(int j=1;j<=i;j++)  System.out.print("* ");
            System.out.println();
        }
        //lower triangle
        for(int i=1;i<row;i++){
            for(int s=i;s>0;s--)     System.out.print(" ");
            for(int j=row-i;j>0;j--) System.out.print("* ");
            System.out.println();
        }
    }
}

Reply

can u please give the solution for the following SERIES:
0,1,2,3,6
I want the first 10 numbers of the series

Reply

For the above series, use this code:
class series {
    public static void main (String args[]){
        int num[] = new int[3];
        for(int i=1,n=0;i<=10;i++){
              if(i<=3){
                  System.out.print(n+", ");
                  num[i-1]=n;
                  n++;
              } else{
                    int next = 0;
                    for(int j=0;j<3;j++) next += num[j];
                    System.out.print(next+" ,");
                    num[0]=num[1]; num[1]=num[2]; num[2]=next;
              }    
        }
    }
}

Reply

thank you! can you also help with automorphic numbers??

Reply

Yes we will help for automorphic number program! What's the program? Leave your question/program....

Reply

Hey how do i print
P
PO
POD
PODA
PODAR

Reply

This is the code for making all the text patterns like this...
class series{
    public static void main(String args[]){
        String txt = "PODAR";
        for(int i=1;i<=txt.length();i++){
            System.out.println(txt.substring(0, i));
        }
    }
}

Reply

pls tell me the code for the series
0,1,2,3,6,.................
using for loop

and to find the frequency of each digit present in the number
eg...in 341124
freq of 1=2 nd freq of 4=2.
using for loops

Reply

Hello!
Code for the frequency program is,
public class NewClass{
    public static void main(String args[]){
        int n = 12335;
        int freq[]=new int[10];
        for(int i=0; i<10; i++)
            freq[i]=0;
        int d;
        while(n>0){
            d=n%10; 
            freq[d]++;
            n=n/10;
        }
        for(int i=0; i<10; i++){
                if(freq[i]!=0)
                    System.out.println(""+i+"\t"+freq[i]);
            }
        }
    }

Reply

for your series program please add some more elements to get what's the logic/pattern to print the next numbers if you want to print Tribonacci series than you should check this post: Multibonacci Series Program in Java

Reply

Hi i need code for
1000
0100
0010
0001

Reply

For this pattern try this code:
public class series {
    public static void main ( String arg[] ){
        int ln = 4;
        for(int i=0;i<ln;i++){
            for(int j=0;j<ln;j++){
                if(j==i)    System.out.print("1");
                else        System.out.print("0");
            }
            System.out.println();
        }
    }
}

Reply

how to print pattern like this
1
2 4 6
8 10 12 14 16
16 18 20 22 24 26 28

Reply

Check this code for this pattern,
public class series {
    public static void main ( String arg[] ){
        int ln = 4 , p=1;
        for(int i=0;i<ln;i++){
            if(i==1) p=2;
            for(int j=0;j<=i*2;j++){
                System.out.print(p+" ");
                p+=2;
            }
            System.out.println();
        }
    }
}

Reply

Sir I want a java program which should display the following output
B
LL
UUU
EEEE
JJJJJ

sir I want dis program ASAp

Reply

hello sir, can you help me for codes of these:
4321
-321
--21
---1
and
----4
---343
--23432
-1234321 ("-" means space)

Reply

public class pattern {
    public static void main ( String arg[] ){
        String txt = "BLUEJ";
        for(int i=0;i<txt.length();i++){
            for(int j=0;j<=i;j++){
                System.out.print(txt.substring(i, i+1));
            }
            System.out.println();
        }
    }
}

Reply

Pattern 1st code:
public class series {
    public static void main ( String arg[] ){
        int ln=4;
        for(int i=0;i<ln;i++){
            for(int s=0;s<i;s++)
                System.out.print(" ");
            for(int j=0;j<ln-i;j++)
                System.out.print(ln-i-j);
            System.out.println();
        }
    }
}


Pattern 2nd code:
public class series {
    public static void main ( String arg[] ){
        int ln=4;
        for(int i=0;i<ln;i++){
            for(int s=1;s<ln-i;s++)
                System.out.print(" ");
            for(int j=0,k=ln-1;j<=i*2;j++){
                if(j<=i){
                    System.out.print(ln-i+j);
                } else{
                    System.out.print(k);
                    k--;
                }
            }
            System.out.println();
        }
    }
}

Reply

thank you for your answer. i have a problem more:
4321
-321
--21
---1
--21
-321
4321

Reply

hello guys at code nirvana can u plz help me the following code
A
A B A
A B C B A
A B C D C B A
A B C B A
A B A
A

Reply

I think this is what you need!
public class series {
    public static void main ( String arg[] ){
        int ln=4;
        for(int i=0;i<ln;i++){
            for(int s=0;s<i;s++)
                System.out.print(" ");
            for(int j=0;j<ln-i;j++)
                System.out.print(ln-i-j);
            System.out.println();
        }
        for(int i=1;i<ln;i++){
            for(int s=1;s<ln-i;s++)
                System.out.print(" ");
            for(int j=0;j<=i;j++)
                System.out.print(i-j+1);
            System.out.println();
        }
    }
}

Reply

public class series {
    public static void main ( String arg[] ){
        String txt = "ABCD";
        for(int i=0;i<txt.length();i++){
            for(int s=1;s<txt.length()-i;s++) System.out.print(" ");
            for(int j=0,k=i;j<=i*2;j++){
                if(j<=i) System.out.print(txt.substring(j, j+1)+" ");
                else{
                    System.out.print(txt.substring(k-1, k)+" ");
                    k--;
                }
            }
            System.out.println();
        }
        for(int i=0;i<txt.length();i++){
            for(int s=-1;s<i*2;s++) System.out.print(" ");
            for(int j=txt.length()-i-1,n=0;j>0;j--,n++)
                System.out.print(txt.substring(n, n+1)+" ");
            for(int j=txt.length()-i-2;j>0;j--)
                System.out.print(txt.substring(j-1, j)+" ");
            System.out.println();
        }
    }
}


Just checked your comment! I hope it fast enough (5 min.) So code might be complex but works as you want :)

Reply

1
2 3 2
3 4 5 4 3
4 5 6 7 6 5 4
5 6 7 8 9 8 7 6 5
6 7 8 9 0 1 0 9 8 7 6
7 8 9 0 1 2 3 2 1 0 9 8 7
8 9 0 1 2 3 4 5 4 3 2 1 0 9 8

Reply

What will be the code for this pattern:

1 1
12 21
123 321
1234 4321
1234554321

Reply

public class Pattern{
public static void main(String args[]){
int a=4;
for(int i=4;i>=1;i--){
for(int j=1;j<=i;j++){
System.out.print(a);
}
a--;
System.out.println();
}
int b=2;
for(int k=2;k<=4;k++){
for(int l=1;l<=k;l++){
System.out.print(b);
}
b++;
System.out.println();
}
}
}

Reply

public class Pattern{
public static void main(String args[]){
int a=1;
for(int i=1;i<=3;i++){
for(int j=1;j<=3;j++){
System.out.print(a);
a++;
}
System.out.println();
}
}
}

Reply

can u plz code the above pattern by using while loop...asap..

Reply

class ABC
{
public static void main(Strings args[])
{
int i=0,j=0,n=0;
System.out.print("Enter number of row= ");
Scanner in=new Scanner(System.in);
n=in.nextInt();
for(i=1;i<=n;i++)
{
for(j=1;j<=i;j++)
{
System.out.print(,j);
}
System.out.println( );
}
}
}

Reply

public class series {
public static void main (String args[]){
int in = 5; //change input
for(int i=1;i<=in;i++){
for(int a=in;a > in+1-i && i!=1;a--){
System.out.print(a);
}
for(int j=in;j>=i;j--){
System.out.print(in+1-i);
}
System.out.println( );
}
}
}

Reply

how to write a program to display the following pattern:-
15 14 13 12 11
10 9 8 7
6 5 4
3 2
1

Reply

Hello Nitin

Here's the solution:

public class numberp {
public static void main( String arg[]){
//change t values as your accordingly
for(int i=1,t=4;i<=4;i++,t--){
for(int j=1;j<=5-i;j++){
System.out.print(t);
}
System.out.println(); }

for(int i=1,r=2;i<=3;i++,r++){
for(int j=1;j<=i+1;j++){
System.out.print(r); }
System.out.println();
}
}
}

Reply

check this code:

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

Reply

Hello Sir, Can you explain me the logic of pattern programs ?
what does "i" , "j", "k" and other represent or refer to ?
I cant understand pattern programs. Can you please help me with this ?

Reply

there's no limitation on giving any other name to your variables but we give i,j,k just for testing and learning purposes...
here's the basic meaning:
i = no. of rows in your pattern
j = no. of columns/row
k = any other special condition or value to print in pattern either number or symbol.

This is the simple structure for printing the pattern :
for(int i=0; i<rows; i++){
            for(int j=0; j<=i; j++){
                System.out.print("*");
            }
            System.out.println();
}

rows are either pre-initialised or asked at runtime!

I hope this is useful for you.... I suggest you to practice for better understanding, you can get 100s of pattern asked by others and check our solutions!

Reply

hello sir, can you help me for codes of these:
1
0 1
1 0 1
0 1 0 1

Reply

Hello! Please check comment <50/>

Reply

plz solve ths pattern to print..

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

Reply

the pattern must be in daimond shape

Reply

public class Pat{
public static void main(String args[]){
int k=0;
for(int i=1;i<=4;i++){

if(i%2==0){
k=0;
}
else{
k=1;
}
for(int j=1;j<=i;j++){

System.out.print(k);
if(k==0){
k=1;
}
else{
k=0;
}

}
System.out.println();

}
}
}

Reply

public class Pat1{
public static void main (String args[]){
for(int g=1; g<=1;g++){



for(int i=1;i<=7;i++){


if(i%2==0){

System.out.println();
}
else{
for(int j=1;j<=i;j++){
System.out.print("* ");
}
}

}

System.out.println();


for(int k=1; k<=5;k++){

if(k%2==0){
System.out.println();
}
else{
for(int m=k; m<=5; m++){
System.out.print("* ");

}
}

}

System.out.println();
}
}
}

Reply

Code for this pattern is:
1
2*2
3*3*3
4*4*4*4
4*4*4*4
3*3*3
2*2
1

Code:

public class P1
{
public static void main(String ar[])
{
int i,j,k=1;
for(i=1;i<=5;i++)
{
for(j=1;j<=i;j++)
{
System.out.print(i);

if( i>1 && k=1;i--)
{
for(j=1;j<=i;j++)
{
System.out.print(i);
if( i>1 && k<i)
{
System.out.print("*");
k++;
}
}
k=1;
System.out.println();
}
}
}

Reply

help me for this pattern....
if n=4 then pattern is............
4
3 4
2 3 4
1 2 3 4

the pattern above forms an upper-triangle, which i m not able to
draw @ comment :(

Reply

using while statement

54321
5432
543
54
5
54
543
5432
54321

5
54
543
5432
54321
5432
543
54
5

Reply

hai
------------- *
------------* *
----------* * *
--------* * * *
------* * * * *

Reply

import java.io.*;
class f
{
public static void main(String args[]) throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter the number of words u want to enter:");
int n=Integer.parseInt(br.readLine());
int k=0;
for(int i=1;i<=n;i++)
{
if((i%2)==0)
{
k=k+i-1;
for(int j=1;j<=i;j++)
{
if(j==1){
System.out.print(k--);
}else{
System.out.print("*"+k--);
}

}
System.out.println();

}
else
{ k=k+i;
for(int j=1;j<=i;j++)
{
if(j==1){
System.out.print(k++);
}else{
System.out.print("*"+k++);
}
}
System.out.println();
}
}
}
}

Reply

public class Pat3{
public static void main (String args[]){
int p=14;
for(int i=1; i<=5; i++){
for(int k=1; k<=p; k++){
System.out.print("-");
}
for(int f=1; f<=i; f++){
System.out.print(" * ");

}
p=p-2;
System.out.println();
}
}
}

Reply

public class Pat4{
public static void main (String args[]){
int h=4;
for(int y=1; y<=4; y++){
for(int i=h; i<=4; i++){
System.out.print(i);


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

Reply

123456787654321
1234567_7654321
123456___654321
12345_____54321
1234_______4321
123_________321
12___________21
1_____________1

Reply

Sir I want a java program which should display the following output
BY USING BUFFERED READER

B
LL
UUU
EEEE
JJJJJ

Reply

SIR PLEASE SOLVE THIS PROGRAM
write a program to generate a pattern of a string entered by the user based upon user's choice .

sample input : HONESTY IS THE BEST POLICY

Enter yout choice 1 Enter your choice2
Output: H OUT PUT Y
I S
T E
B T
P Y

Reply

please give us only 1st character
HONESTY IS THE BEST POLICY --- OUTPUT ( H I T B P , Y S E T Y) BY USING BUFFERED

Reply
«Oldest   ‹Older   1 – 200 of 1065   Newer›   Newest»

Make sure you tick the "Notify Me" box below the comment form to be notified of follow up comments and replies.