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. 

1225 Comments Leave new

«Oldest   ‹Older   801 – 1000 of 1225   Newer›   Newest»
This comment has been removed by the author.

***** *****
**** ****
*** ***
** **
*
This is the pattern for n=5.
Please provide the sourcecode in java.

Reply

my pattern is
1 1 1 1 1
1 1 1 1 5
1 1 1 4 5
1 1 3 4 5
1 2 3 4 5

Reply

public static void main(String[] args)
{
//int num=1;
for(int i=1;i<=5;i++)
{
for(int j=1;j<=i;j++)
{
System.out.print(j);

}
System.out.print(" ");
for(int k=i;k>=1;k--)
{
System.out.print(k);
}
System.out.println();
}
}

Reply

public static void main(String[] args)
{
//int num=1;
for(int i=1;i<=5;i++)
{
for(int j=1;j<=i;j++)
{
System.out.print(j);

}
System.out.print(" ");
for(int k=i;k>=1;k--)
{
System.out.print(k);
}
System.out.println();
}
}

Reply

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

System.out.println();
}
}

Reply

public class Test2 {

public static void main(String[] args) {
int l=6;
for(int i=0; i<5; i++){
for(int j=1; j<6; j++){
if(l<=j && i!=0)
System.out.print(j);
else
System.out.print(1);
}
l--;
System.out.print("\n");
}


}
}

Reply

can u tell me the code for pattern
1
1*2
1*2*3
1*2*3*4
1*2*3*4*5

Reply

WAP to create the following pattern:
* * * *
* * *
* * * *
* * *
* * * *
* * *
* * * *
can you please solve this

Reply

plz help
1
2 3 4
5 1 2 3 4
5 1 2 3 4 5 1

Reply

Sir
Please help me to print the following
11
12 22
13 23 33
14 24 34 44
15 25 35 45 55

Reply

public class Test4 {

public static void main(String[] args) {
int i=1;
int l=1;
for(int j=0; j<4; j++){
for(int k=0; k<l; k++){
System.out.print(i);
i++;
if(i==6)
i=1;
}
l=l+2;
System.out.print("\n");
}

}

}

Reply

please send the code for this pattern
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

sir please tell me the code of this



1
22
333
4444
55555

Reply

1
4
9
25
49
121
169
289
361,
.... i am ramakoti, sir please provide code and count count the digits which have 4

Reply

sir i want below pattern code and count the digits which have 4 digit
1
4
9
25
49
121
169
289
361
529
841
961
1369.......n

Reply

sir please provide code for this pattern and count the no of digits which have 4 number
1
4
9
25
49
121
169
289
361
529
841
961......N

Reply

import java.util.*;

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

Reply

code for the output::
2
35
71113
17192329
3137414347

Reply

Sir plz tell me
A
A B
B C D
C D E F
D E F
E F
F

Reply

hi how do i code this in java?

01
02 06
03 07 10
04 08 11 13
05 09 12 14 15

given that i accepted input from a user which is 5?

Reply

1111
333
55
7
pls send code this patterns

Reply

15 10 6 3 1
14 9 5 2
13 8 4
12 7
11
plzz tell the code for this

Reply

how to do this pattern?
1
3 1
5 3 1
7 5 3 1
9 7 5 3 1

Reply

how to do this pattern?
1
3 1
5 3 1
7 5 3 1
9 7 5 3 1
Reply soon plz

Reply

how to do this pattern?
1
3 1
5 3 1
7 5 3 1
9 7 5 3 1
Reply soon plz

Reply

Sir,can you please solve the following pattern:

A
B
ABCBA
B
A

Reply

Please can I know the solution using only for loops

1
21
321
4321
54321
654321

I know how to print those blank spaces and the number pattern indivisually but not together :(
please help!

Reply

Please can I know the solution using only for loops

1
21
321
4321
54321
654321

I know how to print those blank spaces and the number pattern indivisually but not together :(
please help!

Reply

Could you help me with this program please?
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

please tell me this ?
1 1
2 1
3 2
4 2
5 3

Reply

for(int i=1;i<=5;i++)
{
for(int j=1;j<=i;j++)
{
System.out.print(j);
}
if(i!=5)
{
System.out.print(" ");
}

for(int j=i;j>=1;j--)
{
System.out.print(j);
}

System.out.println();
}

Reply

hey can you please guide me to get the pattern
* * * * *
* *
* *
* *
* * * * *

Reply

sir i want output for this number pattern
3 4 7
7 5 12
12 6 18

Reply

Hi,

Ur blog is veryuseful for programmers.

I wanted for spiral matrix

5 6 7
4 9 8
3 2 1

Reply

Hi,

Ur Blog is very useful and improves skills for an programmer

I am trying for an spiral matrix.. could u help it out

5 6 7
4 9 8
3 2 1

Reply

please help me to print this pattern
1
3 5
7 9 11

Reply

Sir, please solve this problem.
15
14 10
13 9 6
12 8 5 3
11 7 4 2 1

Reply

i am telling the output which i want:

Enter any sentence: abcd

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

Reply

it is actually not like this
its a big capital A B C D

__***___****___***__****
*-----*_*---*_*---*_*---*
*-----*_*---*_*_____*---*
*******_****__*_____*---*
*-----*_*---*_*_____*---*
*-----*_*---*_*---*_*---*
*-----*_**** __***__****

Reply

please provide me code about the given output.

jjjjjjjjj aa v v aa
j a a v v a a
j a a v v a a
j a a v v a a
j a a v v a a
j a a v v a a
j a a v v a a
j a a a a a a a a v v a a
j a a v v a a a a a a a a a
j a a vv a a

Reply

how to output the following pattern in java
1 2 3
4 5 6
7 8 9

Reply

Could you please help me find the code for this pattern?
1
2
1 2 3 2 1
2
1

Reply

answer the following pattern
1
24
135
2468
13579

Reply

Hi Zankar - find the code for your pattern

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

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

Reply

Hi could u please tell me how to solve this pattern???
5
45
345
2345
12345

Reply

class Mysample
{

public static void main (String[] args)
{
for (int i=1;i<=6;i++)
{
for (int j=1;j<=6 ;j++)
System.out.print(i+" ");
else { System.out.print(i+1);}
c++;
} }
else {
for (int j=1;j<=6 ;j++)
{
if (j<=1)
System.out.print(i+1+" ");
else { System.out.print(i+" ");}
c--;
}
}
System.out.println();
}
}
}

Reply

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

plz solve

Reply

Code for following output....
567
498
321

Reply

Give me a code for this sir
12345
1234
123
12
1

Reply

0000*
000*0
00*00
0*000
*0000
How to code this sir??

Reply

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

Reply

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

Reply

Hello Sir, can u give me code for this pattern
1
3 5
7 9 11

Reply

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

Reply

Sir can u help me with this ptterrn , its very difficult for me to solve
1 2 3 4
12 13 14 5
11 16 15 6
10 9 8 7

Reply

Can u help me to write generalized code. For this pattern
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

Sir i need code for this 1...

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

Reply

sir can you help me in doing the program
5
4 5
3 4 5
2 3 4 5
1 2 3 4 5

Reply

Can u give the code for the following pattern??
567
498
321

Reply

I want a java program which should display the following output .
4321
1234
4321
1234

Reply

code for to print ?
1¹ 2² 3³ 4⁴ 5^5
1¹ 2² 3³ 4⁴
1¹ 2² 3³
1¹ 2²

Reply

Please help me below pattern
* * * * *
* * * *
* * *
* *
*

Reply

Please provide the code for below pattern

1
1 2
3 5 8
132134
5589144233

Reply

sir can you give the coding for
1
3 3
5 5 5
7 7 7 7
9 9 9 9 9

Reply

Input: 5 5, stands for 5 rows and 5 columns!
Produce the following pattern given the input:
11111
12221
12321
12221
11111

How to code this? Should be able to take any arbitrary input of rows and columns

Reply

What will be the code for this pattern
1
2 3 2
4 5 6 5 4
7 8 9 0 9 8 7
1 2 3 4 5 4 3 2 1
6 7 8 9 0 1 0 9 8 7 6
2 3 4 5 6 7 8 7 6 5 4 3 2

Reply

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


code for this program

Reply

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


code for this program

Reply

1
12
123
1234
12345

textname
textname
textname
textname
textname

process complete

HOW TO DO THAT ?

Reply

please tell me java code for

####
##
$$$$$
**
****

Reply

can anyone help me with this program

-------C
------CO
-----COM
----COMP
---COMPU
--COMPUT
-COMPUTE
COMPUTER

here - means space.the program should be written using forloop

Reply

Hai sir can you help me ? I want diplay a pattern with 's''y''a''z''a' in star pattern can you help me ?

Reply
This comment has been removed by the author.

----------------------- 1
--------------------2 15 3
------------------4 5 66 6 7
---------------8 9 10 189 11 12 13
pls solve this pattern

Reply

Hi Can you help me for this below pattern

a
ab
bac
abcd
cabde
eadcbf

Reply

How to print this 6 please help
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1

Reply
This comment has been removed by the author.

Sir I want a java program which should display the following output

1
3 5
7 9 11

Reply

package module1;

public class Question_IO {

static int o = 1;
public static void main(String[] args) {

int i,j,k;


for ( i = 1; i <= 4; i++) {
for (j = i; j <= i; j++) {
for (k = 0; k <j; k++) {
System.out.print(o + " " );
o++;
}
}
System.out.println();
}
}
}

Reply

Code for this
1
21
321
4321
54321

Reply

Code for this
1
21
321
4321
54321

Reply

Code For

input Value = 5 (USING SCANNER)

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

Reply

help need code for this
thanks :)
1*********
12********
123*******
1234******
12345*****
123456****
1234567***
12345678**
123456789*
1234567890

Reply

please exlain wid code for
3 3 3
3 1 3
3 2 3
3 3 3

Reply

please exlain wid code for
3 3 3
3 1 3
3 2 3
3 3 3

Reply

what will code of
1
22
333
4444
55555

Reply

what will code of
p
pr
pri
priy
priye
priyes
priyesh

Reply

what is the code for que. like this

if we enter 5
1 2
5 4 3

and if we enter 8


7 8
6 1 2
5 3 4

and if we enter 16 then the output should be like this


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

Reply

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

Reply

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

Reply

please print this pattern for me

0
909
89098
7890987
678909876
56789098765

Reply

can u help me to print the pattern using while loop
1
12
123
1234
12345

Reply

I need this code
1234567654321
123456 654321
12345 54321
1234 4321
123 321
12 21
1 1

Reply

I need this code
1234567654321
123456 654321
12345 54321
1234 4321
123 321
12 21
1 1

Reply

******
***** ***** For this?
**** ****
*** ***
** **
* *

Reply

Program for the pattern:
*
*#
*#*
*#*#*

Reply

Help me sir for this pattern
1
211
312
413
514
615
716
817
918
1019
20 this sequence continue UpTo 100 plzzz help me sir

Reply

A
BC
DEF
GHIJ
PLS GIVE CODE FOR THIS ASAP

Reply

Plz let me know this code....
11
1221
123321
1221
11




1
121
12 21
12 21
12 21
121
1

Reply
This comment has been removed by the author.
This comment has been removed by the author.

*
* *
* * *
* * * *
how to generate this pattern?

Reply

i need the logic for following
if input is 3, then the output is
7 8 9
6 1 2
5 4 3

and if the input is 4,
7 8 9 10
6 1 2 11
5 4 3 12
16 15 14 13

Reply

Sir please solve this
WAP TO PRINT

1
101
10101
1010101

Reply

DEAR SIR PLEASE FIND WAP TO PRINT THE FOLLOWING PATTERN USING TRY CATCH BLOCK
a) 1
101
10101
1010101

b) *
0 0
* * *
0 0 0 0
* * * * *
0 0 0 0
* * *
0 0
*

c) 1
1 2 1
1 3 3 1
1 4 6 4 1
15 10 10 5 1

Reply

DEAR SIR PLEASE FIND
WAP TO PRINT THE FOLLOWING PATTERNS USING TRY CATCH BLOCK

a) 1
101
10101
1010101

b) *
0 0
* * *
0 0 0 0
* * * * *
0 0 0 0
* * *
0 0
*

c) 1
1 2 1
1 3 3 1
1 4 6 4 1
15 10 10 5 1

Reply

your way of solving problem is much easy. thnkyou

Reply

sir can u please send code for this pattern please sir!! thak you
1

2 4

3 6 9

4 8 12 16

5 10 15 20 25

Reply

sir can u help me in printing this pattern please very urgent its my homework sir!!! thank you sir!!
1

2 4

3 6 9

4 8 12 16

5 10 15 20 25

Reply

pls i want to this.....

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

Reply

Hello Chiru N, here is the program for your pattern.

public class Pattern
{



public static void main(String[] args)
{
int m=6; int r=0;

for (int i= 0;i<m;i++)
{
for (int j=1;j<=1;j++)
{
System.out.print(i+1+" ");

}
int n=0; int u=4;
for (int k=1;k<=r;k++)
{
System.out.print(m+i+n+" ");


n=n+u;
u--;
}
r++;
System.out.println("");
}}


}

Reply

Here is the program for your pattern.

public class Pattern
{
public static void main(String[] args)
{
int m=5; int r=0;
for (int i= 1;i<=m;i++)
{
for (int j=1;j<=1;j++)
{
System.out.print(i+" ");
}
int u=2;
for (int k=1;k<=r;k++)
{
int v=u*i;
System.out.print(v+" ");

++u;
}
r++;
System.out.println("");
}}
}




Reply
This comment has been removed by the author.

public class Pattern
{

public static void main(String []args)
{
int n=4; int p=0;
for (int i=1;i<=n;i++)
{
for(int j=1;j<=i+p;j++)
{
if (j%2==0)
{
System.out.print(0);
}
else
{
System.out.print(1);
}
}
p++;
System.out.println("");
}

}
}

Reply

public class Pattern
{

public static void main(String []args)
{
int n=4;
for (int i=1; i<=n;i++)
{
for (int j=1;j<=i;j++)
{
System.out.print("*");
}
System.out.println("");
}
}
}

Reply

public class Pattern
{

public static void main(String []args)
{
int n=5;
for (int i=1;i<=n;i++)
{
for(int j=1;j<=i;j++)
{
if (j%2==0)
{
System.out.print("#");
}
else
{
System.out.print("*");
}
}

System.out.println("");
}

}
}

Reply

public class Pattern
{

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

}
}

Reply

public class Pattern
{

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

Reply

hi Smita Tandon here is your code:-

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

Reply

its good but turn it into more easy as easy:

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

Reply

hi please
A
BC
DEF
GHIJ
KLMNO

HELP .....JUST NORMAL INT I,J NO LN OR OTHER FNCTIONS PLAESE

Reply
This comment has been removed by the author.

Hello harry singh, here is the program for your pattern...!

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

Reply

code for
1
2*2
3*3*3
4*4*4*4
4*4*4*4
3*3*3
2*2
1

Reply

Check this code for
1
2*2
3*3*3
4*4*4*4
4*4*4*4
3*3*3
2*2
1

public class Pattern
{
public static void main(String[] args)
{
int p=0;
for (int i=1;i<=4;i++)
{
for (int j=1;j<=i+p;j++)
{
if(j%2==0) {System.out.print("*");}
else {System.out.print(i); }
}
p++;
System.out.println("");
}

int q=3;
for (int i=4;i>=1;i--)
{
for (int j=1;j<=i+q;j++)
{
if(j%2==0) {System.out.print("*");}
else {System.out.print(i); }
}
q--;
System.out.println("");
}
}
}

Reply
This comment has been removed by the author.

program for
1
24
135
2468
13579



public class Mysample
{
public static void main (String args[])
{
for(int i=1;i<=5;i++)
{
int m=1; int n=2;
for (int j=1;j<=i;j++)
{
if(i%2!=0) {System.out.print(m); m+=2;}
else {System.out.print(n); n+=2;}
}
System.out.println();
}
}
}

Reply

11111
2222
333
44
5
how to print this pattern

Reply
This comment has been removed by the author.

----1
---32
--654
-10987

- refers to spaces

Reply
This comment has been removed by the author.

----1
---32
--654
-10987

- refers to spaces

Reply

----1
---32
--654
-10987

- refers to spaces

Reply

----1
---32
--654
-10987

- refers to spaces

Reply

program for
11111
2222
333
44
5


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

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

Reply

Program for
1
32
654
10987

public class Pattern
{
public static void main(String[] args)
{
int n=4; int m=n; int p=1;
for(int i=1;i<=n;i++)
{
for (int j=1;j<=m;j++)
{
System.out.print(" ");
}
int q=p;
for(int k=1;k<=i;k++)
{
System.out.print(q);
q--;
}
System.out.println("");
p=p+i+1;
m--;
}
}
}

Reply

The above program is for this pattern,
----1
---32
--654
-10987

Reply

11
11 12
11 12 13
11 12 13 14

my progress till far is,according to the logic

class Series {
public static void main( String arg[]){
int n=11;
for(int i=1;i<4;i++){

for(int j=1;j<=i;j++)

System.out.print(+n);
n++;
}
{ System.out.println();}
}
}

help me out

Reply

11
11 12
11 12 13
11 12 13 14

my progress till far is,according to the logic

class Series {
public static void main( String arg[]){
int n=11;
for(int i=1;i<4;i++){

for(int j=1;j<=i;j++)

System.out.print(+n);
n++;
}
{ System.out.println();}
}
}

help me out

Reply

11
11 12
11 12 13
11 12 13 14

my progress till far is,according to the logic

class Series {
public static void main( String arg[]){
int n=11;
for(int i=1;i<4;i++){

for(int j=1;j<=i;j++)

System.out.print(+n);
n++;
}
{ System.out.println();}
}
}

help me out

Reply

Please do this program for me.
12345
2345
345
45
5

Reply

Program for
11
11 12
11 12 13
11 12 13 14



public class Series {
public static void main( String arg[]){

for(int i=1;i<=4;i++)
{
int n=11;
for(int j=1;j<=i;j++)
{

System.out.print(n+" ");
n++;
}
System.out.println();
}
}
}

Reply

Program for
1234567
12345
123
1


public class Pattern {
public static void main( String arg[]){
int n=7;
for(int i=1;i<=4;i++)
{
for(int j=1;j<=n;j++)
{
System.out.print(j);
}
System.out.println();
n=n-2;
}
}
}

Reply

Program for
12345
2345
345
45
5

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

}
}
}

Reply

can u temme the code for :

1 2 3 4
10 5
9 8 7 6

Reply

can u temme the code for :

1 2 3 4
10 5
9 8 7 6

Reply

Program for

1-2-3-4
10----5
9-8-7-6
(Note: "-" is used here instead of "space")

public class Pattern
{
public static void main( String[] args)
{
int m=1; int p=10;
for(int i=1;i<=3;i++)
{

for(int j=1;j<=4;j++)
{
if(i==1)
{ System.out.print(m+" ");
m++;}

else if(i==2)
{
if((j==2)||(j==3))
{
System.out.print(" ");
}
else
{System.out.print(p);
p=p/2;}

}
else
{

System.out.print(m+" ");
m--;
}

}

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

Reply

number pattern

7
14 15
28 29 30 31
56 57 58 59 60 61

Reply

number pattern

7
14 15
28 29 30 31
56 57 58 59 60 61

Reply

Here is the code guys...
package mypack2;

import java.util.Scanner;

public class Testing{
public static void main( String arg[]){


Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
int c=n;
int i,j;
int t;
for(i=1;i<=n;i++){

for(j=1;j<=c;j++){

System.out.print(c);

}
System.out.println();
c--;
}
t=c+2;

for(i=1;i<=n-1;i++){

for(j=1;j<=t;j++){


System.out.print(t);

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

Reply

package mypack2;

import java.util.Scanner;

public class Testing{
public static void main( String arg[]){


Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
int c=1;
for(int i=1;i<=n;i++){

for(int j=1;j<=n;j++){



if(j==n){

System.out.print(" "+ ++c);

}
else{

System.out.print(" "+c);

}

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

Reply

i want the code for blow pattern
7 8 9 10
6 1 2 11
5 4 3 12
16 15 14 13


Reply

Program for
7
14 15
28 29 30 31
56 57 58 59 60 61


public class Pattern {
public static void main( String arg[]){
int n=7; int m=2;
for(int i=1;i<=4;i++)
{
int q=n;
if(i==1) {m=1;}
for(int j=1;j<=m;j++)
{
System.out.print(q+" ");
q++;
}
n=n*2;
if (i==1) {m=m+1;}
else {m=m+2;}

System.out.println();

}
}
}


Reply

Program for
7-8-9-10
6-1-2-11
5-4-3-12
16-15-14-13

(Note: here "-" is used instead of "whitspace")


public class Pattern
{
public static void main( String[] args)
{
int n=4; int m=n;
int[][]a=new int[n][m];
int d=1; int e=1;
for(int i=1;i<=(n*n);i++)
{
if((i==2) || (i==8)|| (i==9)|| (i==10)) {++e;}
else if((i==4) || (i==5)|| (i==14)|| (i==15) ||(i==16)) {--e;}
else if((i==3) || (i==11)|| (i==12)|| (i==13)) {++d;}
else if((i==6) || (i==7)){--d;}

a[d][e]=i;
}

for (int j=0;j<n;j++)
{
for(int k=0;k<n;k++)
{
System.out.print(a[j][k]+"\t");
}
System.out.println("");
}
}
}

Reply

public class T{


public static void main(String[] arr)
{
int c=1,i,j,k;
int n,m=3,z=3;
for(i=0;i<5;i++){

n=5;
for(k=1;k<=i;k++){

if(i>=1)
System.out.print(" -");

}
for(j=1;j<=5-i;j++){


System.out.print(" "+n--);


}


System.out.println();

}
for(i=3;i<=6;i++){
n=5;
if(m==0){

break;
}
else
{

for(k=1;k<=m;k++){

System.out.print(" -");

}
}
if(z<1){
break;
}
else
{
for(j=5;j>z;j--){



System.out.print(" "+j);



}
}
m--;
z--;
System.out.println();
}


}
}

Reply

hi i want code for
1
3*2
4*5*6
10*9*8*7
11*12*13*14*15

Reply

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


public class Pattern
{
public static void main( String[] args)
{
int n=5; int p=0; int m=1;
for(int i=1;i<=n;i++)
{
for (int j=1;j<=(i+p);j++ )
{
if(j%2!=0)
{
System.out.print(m);
if(i%2==0){m--;}
else{++m;}
}
else
{
System.out.print("*");
}

}
if((i==1)){m=m+1;}
if((i==2)||(i==3)){m=m+3;}
else if(i==4){m=m+5;}
System.out.println();
p++;
}
}
}

Reply

In the above code neglect int n=7; (it is unused variable)

Reply

Sir I want a java program which should display the following output

input:4
output:
4
8 20 32 44
12 24 36 48
16 28 40 52

Reply

Program for
54321
4321
321
21
1

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

Reply

4
8 20 32 44
12 24 36 48
16 28 40 52 that code is given below......
class ForthMultiplication
{
p.s.v.m(Strings a[])
{
int a=2,b=2,n=4;
s.o.pln(n);
for(int i=1;i<=3;i++)
{
for(int j=1;j<=4;j++)
{
s.o.p(n*a+" ");
a+=3;
}
b++;
a=b;
s.o.pln();
}
}
}

Reply

Program for
input:4
output:
4
8 20 32 44
12 24 36 48
16 28 40 52



public class Pattern
{
public static void main( String[] args)
{
int n=4;
// instead of entering n value here, you can get input from user using scanner.
int m;
for(int i=1;i<=n;i++)
{
if (i==1) {m=n/n;}else{m=n;}
int k=n*i;
for(int j=1;j<=m;j++)
{
System.out.print(k+" ");
k=k+((n-1)*n);
}
System.out.println("");
}
}
}

Reply
This comment has been removed by the author.
This comment has been removed by the author.

sir
Thanks for solve my problem
But i don't get proper output as per my pettern.

As per your code New Output is :
4
8
20
32
44

12
24
36
48

16
28
40
52

Reply

sir please help in solving this:
write a class that stores and prints numbers given to it.the numbers are given to this class by calling store method. this method accepts one number at a time. the numbers are printed by calling the print method. numbers should be printed in order they were given to the class

Reply

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

Reply

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

Reply
This comment has been removed by the author.

please help in making the pattern shown below
1
_2
__3
___4
____5

Reply

Program for
1
_2
__3
___4
____5


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

Reply

Show me the pattern for this please:

01 02 07 08 13 14 19 20 25 26
03 04 09 10 15 16 21 22 27 28

05 06 11 12 17 18 23 24 30 31

Reply

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

Reply

Please help how do you do this
1 = 1
1 + 2 = 3
1 + 2 + 3 = 6
1 + 2 + 3 + 4 = 10
1 + 2 + 3 + 4 + 5 = 15
1 + 2 + 3 + 4 + 5 + 6 = 21
1 + 2 + 3 + 4 + 5 + 6 + 7 = 28
1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 = 36
1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 = 45
1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 = 55

Reply
This comment has been removed by the author.

Hello,
How to Print
1*2*3
7*8*9
4*5*6
where n=3

Reply

Program for
1*2*3
7*8*9
4*5*6

class Pattern
{

public static void main(String []args)
{
int n=3;
int m=1; int p=(n*2)+1;
for(int i=1;i<=n;i++)
{
if(i!=2){
for(int j=1;j<(n*2);j++)
{
if(j%2!=0)
{System.out.print(m);
m++;}
else
{
System.out.print("*");
}
}}
else
{
for(int j=1;j<(n*2);j++)
{
if(j%2!=0)
{System.out.print(p);
p++;}
else
{
System.out.print("*");
}
}
}

System.out.println("");

}
}
}

Reply
This comment has been removed by the author.
«Oldest   ‹Older   801 – 1000 of 1225   Newer›   Newest»

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