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   201 – 400 of 1225   Newer›   Newest»

PRINT THE SUM OF THE SERIES:
1-2+3-4+5-6+7..........n

Reply

hello sir i want a code to print 3rd math table.........the result must be odd numbers in the table that means only odd numbered result have to print,should be in line by line format.........thank you.

Reply

Hello, below code can help you

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

Reply

SOOOS
OSOSO
OOSOO
OSOSO
SOOOS
can any one help me out this pattern.........

Reply

i want to learn java...these are my basic questions...
Q1 : Check whether number is prime or not if prime then print all prime number upto 50 and generate sum .
Q 2 : Write a program to find the product of the sums of all odd & even digits in a given number ?
Q 3 : Write a program to find the number & sum of all Integers 100>no.>200 that is divisible by 7 ?
Q 4 : Write a program in java to find the largest of 3 numbers by using conditional operator ?
Q 5: Write a program in java to sort the elements of an array in ascending order by using bubble sort ?
Q 6 : Write a program in java to implement matrix multiplication ?
Q 7 : Check number is even or not if even then print list in reverse order [range 1 -60]
Q 8 : Write a program in java to display the first 10 numberof Fibonacci series and find factorial of the last number of the produced Fibonacci series.
Q 9 : Write a simple program to implement constructor ?

Reply

what is the coding for this patterns

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

&

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

Reply

can you help me for this pattern

1
0 0
1 1
0 0
1

Reply

public class Third {

public static void main(String[] args) {

int y=1;
int m=1;
for(int i=1;i<=5;i++){

if(i==1 || i==5){
System.out.print(m);
}
else{
if(i%2==0){
y=0;
}
else{
y=1;
}
for(int k=1;k<=2;k++){
System.out.print(y+" ");

}
}

System.out.println();
}
}

}

Reply

public class Third {

public static void main(String[] args) {


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





}

}

Reply

Thanks Anand prakas yadav for solving everyone's problem. We really appreciate this!

Reply

public class Third {

public static void main(String[] args) {

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


}

Reply

output is-------


1
121
12321
1234321
123454321
12345654321
1234567654321
123456787654321
12345678987654321

Reply

sir we solve the following pattern in how many ways :
------1
-----121
---12321
-1234321
---12321
-----121
-------1

Reply soon SiR. thank U :)

Reply

package abc;

public class Six {


public static void main(String[] args) {
// TODO Auto-generated method stub
int v=4;
int r=2;
for(int i=1;i<=4;i++){
for(int l=1;l<=v;l++){

System.out.print("-");

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

v=v-1;
System.out.println();
}
for(int t=1;t<=3;t++){
for(int y=1;y<=r;y++){
System.out.print("-");

}

int u=3-t;
for(int j=1;j<=4-t;j++){
System.out.print(j);
}
for(int k=1;k<=3-t;k++){
System.out.print(u);
u--;
}

r=r+1;
System.out.println();

}


}

}


you can solve this pattern in many ways like as using while or other methods.Because you can solve any problem in many ways.

Reply

thank U sir . u got programming powers :D

Reply

can u pls help me get coding for my programs

Reply

for this pattern...
0
0 2
0 2 4
0 2 4 6
0 2 4 6 8

Reply

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

can you solve this ??

Reply

Please help me asap
11111
22221
33321
44321
54321

Reply

public class Example {

public static void main(String[] args) {
// TODO Auto-generated method stub



for(int i=1; i<=5;i++){
int s=i;
for(int g=1;g<=6-i;g++){

System.out.print(i);

}

for(int h=1;h<=i-1;h++){

System.out.print(s-1);
s--;
}
System.out.println();
}


}

}

Reply

public class Example {

public static void main(String[] args) {
// TODO Auto-generated method stub

int e=0;

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

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

System.out.print(e+" ");
e+=2;

}

e=0;
System.out.println();
}

}

}

Reply

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


this 1 sir whats the code

Reply

1
3 5
7 9 11
13 15 17 19
send me program for this pattern

Reply

sir plzzzzzz help

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

Reply

public class Example4 {

public static void main(String[] args) {
// TODO Auto-generated method stub

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


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

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

}

}

Reply

public class Pattern {


public static void main(String[] args) {
// TODO Auto-generated method stub

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

}

}

Reply

public class Man {


public static void main(String[] args) {

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

}

}

Reply

hello can you help me printing this
***
**
*

Reply

sir plz help me for this pattern
15 14 13 12 11
10 9 8 7
6 5 4
3 2
1

Reply

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

Reply

finally i done.
------------------------------------------------------------------------------------
class NumPattern
{
public static void main(String args[])
{
int ln=5;
int x=15;
for(int i=1;i<=5;i++)
{
for(int j=ln;j>=i;j--)
{
System.out.print(x+" ");
x--;
}
System.out.println();
}
}
}

Reply

Sir please give me a java code for the pattern
..........1
.......1 2 1
....1 2 3 2 1

Reply

Sir please..................its very urgent

Reply

Please check comment <30/> above, same program solved there!

Reply
This comment has been removed by the author.

Hello Akshay!
Please check comment no. <39/> or <96/> above.... same question solved there!

Reply

Looks like you didn't check the above comments I mentioned :)
Ok, so you can grab your code with correct spacing you want below:

class Main1 {
    public static void main(String Args[]) {
        int max = 4;    //max no. in series
        //Upper Triangle
        for(int i=1;i<=max;i++){
            for(int s=0;s<max-i;s++){
                System.out.print(" ");  //Spacing
            }
            for(int j=1;j<=i;j++){
                System.out.print(j);    //ascending print
            }
            for(int k=i-1;k>=1;k--){
                System.out.print(k);    //descending print
            }
            System.out.println();       //new line
        }
        //Lower Triangle
        for(int i=1;i<=max-1;i++){
            for(int s=max-i;s<max;s++){
                System.out.print(" ");  //Spacing
            }
            for(int j=1;j<=max-i;j++){
                System.out.print(j);    //ascending print
            }
            for(int k=max-i-1;k>=1;k--){
                System.out.print(k);    //descending print
            }
            System.out.println();       //new line
        }
    }   //end of main
}


Hope that's what you looking for!

Reply

Hi sir your website is very helpful , thanks sir
Can I get the code for these pattern s
123454321
1234 4321
123 321
12 21
1 1


And
1
121
12321
1234321

Reply

Hello!
Kindly scroll to top and check comment no. 11 and 41 for both of your questions solution respectively....

Reply

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

Reply


class Main1 {
    public static void main(String Args[]) {
        int rows=5 , i , j , k , print;
        for( i=1; i<=rows; i++ ){
            for( j=rows-i,k=0,print=i; j>=0; j--,k++ ){
                System.out.print(print+" ");
                print+=rows-k;
            }
            System.out.println();
        }
    }
}

Reply

pls sir print the this name=sagar
in the start pattern

Reply

pls sir print the this name=sagar
in the start pattern

Reply

Sir can we right the last for loop like this?
for (int j=0; j <i; j++, cout++)

Reply

Yes Prajwal we can write like this as well

Reply

sir please help me with this java program

-------*
------*1*
----*121*
---*12321*
--***********

Reply

Your prog:



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


Regs

Reply

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

Reply

SIR CAN YOU GIVE ME CODE FOR THE FOLLOWING CODE:
A
AB
ABC
ABCD
ABCDE

Reply

Sir,
I need help in this program :

123456789
2345678
34567
456
5
456
34567
2345678
123456789

Reply

Better program for pattern 4 without using another r variable.
package patterns;

public class Bow_number_pattern {
public static void main(String[] args) {
/* 1
* 1 2
* 1 2 3
* 1 2 3 4
* 1 2 3 4 5
* 1 2 3 4
* 1 2 3
* 1 2
* 1
*/
int i,j;
int increase_loop_count=0,decrease_loop_count=1;
while(decrease_loop_count>=1)
{
if(increase_loop_count==0)
{
for(i=1;i<=5;i++)
{
for(j=1;j<=i;j++)
System.out.print(j+" ");
System.out.println();
}
increase_loop_count++;
}
else
{
for(i=1;i<=5-1;i++)
{
for(j=1;j<=5-i;j++)
System.out.print(j+" ");
System.out.println();
}
decrease_loop_count--;
}

}

}

}

Reply

hello sir, could u plz help me out in getting this pattern?
1
01
101
0101
10101

Reply

what will be the code for this pattern?
1A 3B 5A
1B 3A 5B
2A 4B 6A
2B 4A 6B

Reply

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++)
{
System.out.print(j);
}
if(i==n)
{
System.out.print("");
}
else
System.out.print(" ");
for(int k=i;k>=1;k--)
{
System.out.print(k);
}
System.out.println();
}
}
}

Reply

A B C D E D C B A
A B C D D C B A
A B C C B A
A B B A
A A
pls help me out find the code fr dis program

Reply

pls sir can u help me solve dis program plzzzzz!!!!
1. 123456789
2345678
34567
456
5
456
34567
2345678
123456789

Reply

Sir.. Plz help me to solve this..

___2_________4____
_2_4_2_____3_4_3_
2_4_6_4_2_3_4_3_2
_1_3_1_____3_4_3__
___1_________4_____


Plz.. Reply as soon as possible.. (__ its space.. Hope u can understand)

Reply

SIR
Could you tell me the code for this following pattern
1
333
55555
7777777
55555
333
1

Reply

Pl help me with this Patten
------------1
---------1 2
------1 2 3
---1 2 3 4
1 2 3 4 5
- spaces can be anything but alignment should be maintained as shown pl help me

Reply
This comment has been removed by the author.

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

Reply

class PatternsDemo
{
public static void main(String[] ar)
{
int n=7;
for(int i=1;i<=n;i+=2)
{
System.out.println("");
for(int j=1;j<=i;j++)
{
System.out.print(i);
}
}
for(int i=n-2;i>0;i-=2)
{
System.out.println("");
for(int j=i;j>0;j--)
{
System.out.print(i);
}
}
}
}

Reply

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

Reply

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

Reply

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

Reply

pls tell me the code
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5

Reply

pls sir help me to get the code for
1
1 1
1 1 1
1 1 1 1
1 1 1 1 1

Reply

prg to print prime numbers from 1 to 100

Reply

class Jamer
{
public static void main(String...s)
{
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.print("\n");
}
}
}

Reply

class PrimeNumbers
{
public static void main(String[] ar)
{
int i,j;
for(i=1;i<=100;i++)
{
int count=0;
for(j=1;j<=i;j++)
{
if(i%j==0)
count++;
}
if(count==2)
{
System.out.print(i+"\t");
}
}
}
}

Reply

123456789
2345678
34567
456
5
456
34567
2345678
123456789

Reply

Hi sir,
How do you print the following pattern:

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

Reply

Please tell me the java program for the pattern

1
121
12321
1234321
12321
121
1

Reply

Greetings sir....cud u plz solve these patterns...
1) 1 2 3 4 5
6 7 8 9
10 11 12
13 14
15

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


3) 1 3 5 7 9
3 5 7 9 1
5 7 9 1 3
7 9 1 3 5
9 1 3 5 7


ASAP will be deeply appreciated...thnx n advance.....

Reply

Hi,
please help me to print this pattern
1 6
2 7
3 8
4 9
5 10

Reply

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

Reply

PLEASE TELL ME HOW TO PRINT
3 33 333 3333 33333
3 33 333 3333 33333
3 33 333 3333 33333
3 33 333 3333 33333
3 33 333 3333 33333

Reply

import java.io.*;
class Pat
{ BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
public void main() throws IOException
{ System.out.println("Input a string:");
String str=br.readLine();
System.out.println();
int len=str.length();
for(int i=0; i<len; i++)
{ char ch=str.charAt(i);
for(int j=1; j<i+2;j++)
{
System.out.print(ch);
}
System.out.println();
}
}
}

Reply

what is code for
11111
12221
13331
14441
11111

Reply

sir plz give me the code of this pattern

J
J A
J A V
J A V A
J A V A 2
J A V A 2 J
J A V A 2 J E
J A V A 2 J E E
J A V A 2 J E E 3

Reply

how to print when n is given =2
112
322

Reply

please provide code for following pattern
*
**
***
****
*****

Reply

sorry , following is the pattern i actually wanted to know:
----*
---**
--***
-****
*****

Reply

sir it is not pattern program but can you pls solve these 3 programs

1) to print the roman equivalent of the number which is entered(without using the method directly)
2) to enter a word and print a character only once if it is repeated in the word for ex. if i enter aabbccdd then the output should be abcd.
3) to enter an integer and give the result as the sum of its digits raise to the power of there position.
for ex. if i enter 491 then the output should be 4 to the power 1 + 9 to the power 2 + 1 to the power 3.


pls help sir

Reply

sir please solve this
1
2 3
4 5 6
7 8 9 10
11 12 13 14 15

Reply

how to print
1
23
456
78910
1112131415

Reply

I want a java program which should display the following output

H
HE
HEL
HELL
HELLO
HELL
HEL
HE
H

Reply

****1
***2*
**3**
*4***
5****
*6***
**7**
***8*
****9
with stars!
can i get the correct code for this pattern

Reply

can u help me in printing the following pattern upto a given limit...
for example if iam giving the limit as 12 my output should be
0
0 2
2 4 6
6 8 10 12

Reply

can u help me to print the pattern
0
0 2
2 4 6
6 8 10 12

Reply

can you please help me to print the following
1 2 3 4 5
2 4
3 3
4 2
5 4 3 2 1

Reply

Help me in doing this pattern using loops only:
* * * * * *
*
*
*
*
* * * * *

Reply


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

Reply

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

Reply

Please help me... Thank you..

123454321
1234_4321
123___321
12_____21
1_______1

Reply

please solve the pattern
Sample output for 3 rows
1 3 5
* 2 *
1 3 5

Reply

Hey, Please solve the pattern
(Ques-1)

A
AB
ABC
ABCD
ABCDE

(Ques - 2)

H
HE
HEL
HELL
HELLO
HELL
HEL
HE
H

Reply

please help me sir

Problem Statement: x pattern using 1 and o s center

Generate the following pattern for an input say 1110111 where equal number of 1's can be prefixed and suffixed where 0 must be at the middle position and the total number of digits must be odd.
1 1
1 1
1 1
0
1 1
1 1
1 1

Dos and Donts

Minimum no. of digits should be 3, say 101.
Maximum no. of digits should be 19.
Input should be read as long data type.
(Don't read the input as String type)

please help me sir , this is too complicated

Reply

S
S U
S U S
S U S H
S U S H I
SIR, pls help me to solve this program

Reply

Hello Sir,

Can you please help me with following pattern-

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

Reply

Check comment no. 27 and 64 for source code!

Reply

# # # # # # #
#
#
#
#
#
# # # # # # #
Any one can help me to do this ? :)

Reply

1
2 6
3 7 10
4 8 11 13
5 9 12 14 15
write a program to print above triangle

Reply

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

Reply
This comment has been removed by the author.

what will be the code for
@ # #
@ @ #
@ @ @

Reply

what will be the code for
@ # #
@ @ #
@ @ @

Reply

a
ab
abc
abcd
and so on upto specified number of letters. How do you do it?

Reply

just a correction..
i would like to have the solution program only with two variables(eg..i and j).
thank you

Reply

sir i have another also:-
1 1
12 21
123 321
1234 4321
1234554321

Reply

Check comment no. 1 and 11 for solution of this pattern.

Reply

can you give java source code for the following as fast as possible(very urgent):-
(i)
1
121
12321
1234321
12321
121
1

Reply

pls help me with this pattern prog
1
13
135
1357
13579

Reply

how to print the sum of series..?
1. s=a+a^2/2!+a^3/3!+................a^n/n!
2. s=x/3+x/8+x/15......n
plz reply asap

Reply

Please help to solve this problems
1
3 2
6 5 4
10 9 8 7


4
2 5 7
1 3 6 8 9

Reply
This comment has been removed by the author.

public class Patterns1{
public void main(int n){
for(int i=1;i<=(2*n-1);i++){
if(i<=n)
print(i);
else
print(2*n-i);
System.out.println();
}
}
public void print(int x){
for(int i=1;i<=(2*x-1);i++)
if(i<=x)
System.out.print(i+" ");
else
System.out.print((2*x-i)+" ");
}
}

Reply

could some one please help me with this.. I really appreciate it...
- - 4
- 2 5 7
1 3 6 8 9

Reply

could u send the code for below pattern

*
* *
* *
* *
*

Reply

1
1 2 1
1 2 4 5 1
1 3 5 9 14 15 1


need this pattern..

Thanks

Reply

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

sir, please give the code for this

Reply

Dear sir
please help me
how to print W format out put
* *
* * *
* * * *
* *


Reply

I want code for following pattern
for n=4
1111
1001
1001
1111

n=5

11111
10001
10101
10001
11111

Reply

What about this code:
1***
12**
123*

Reply

public static void main(String[] args) {
// TODO Auto-generated method stub
int n = 5;

for (int i = 1; i <= n; 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.print("\n");
}
}

Reply

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
class pattern
{
public static void main(String args[])throws IOException
{
int n=5;
for(int i=1;i<=n;i++)
{
for(int j=1;j<=i;j++)
{
System.out.print(j);
}
for(int k=i;k>=1;k--)
{
System.out.print(k);
}
System.out.println();
}

}
}

Reply

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
class pattern
{
public static void main(String args[])throws IOException
{
int n=5;
for(int i=1;i<=n;i++)
{
for(int j=1;j<=i;j++)
{
System.out.print(j);
}
for(int k=i;k>=1;k--)
{
System.out.print(k);
}
System.out.println();
}

}
}

Reply

sir I want to know how do u tackle any pattern programs.I want to learn n understand ur logical thinking process ability. plz plz do rply.

Reply

Can you please solve this by today? Its for my computer exam tomorrow...thanks in advance
123454321
1234 4321
123 321
12 21
1 1

Reply

Scroll up and search for comment <11/> or just search your pattern in 'search box' you will find my previous solution for the same pattern.
Best of luck for your exam :)

Reply

Try to create 5 to 10 patterns manually with/without taking any hint you will get the logic what's same in every pattern.....
I suggest you to practice regularly for 3-4 days and try to understand how the numbers (to be printed) are generated and how next value is related to previous values!

Reply

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

Reply

i want this pattern code plz help me sir
111112
311112
311114
511114
511116
and so on

Reply

Sir i want an output as follows:

Enter a string in between A to Z (only odd characters like A or C or E )

ABCDEDCBA
ABCD DCBA
ABC CBA
AB BA
A A

Reply

Sir i want an output as follows:

Enter a string in between A to Z (only odd characters like A or C or E )

ABCDEDCBA
ABCD DCBA
ABC CBA
AB BA
A A

Reply

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

Reply

HI gil,
here program for above pattern


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

Reply

OUTPUT SHOULD BE DISPLAYED AS FOLLOWS:
> Enter an odd character in between A and Z
> User will enter "E"nce the user enter E. the output displayed should be as followed

ABCDEDCBA
ABCD DCBA
ABC CBA
AB BA
A A

Reply

11
21 22
31 32 33
41 42 43 44
51 52 53 54 55

Reply

11
21 22
31 32 33
41 42 43 44
51 52 53 54 55

Reply

11
21 22
31 32 33
41 42 43 44
51 52 53 54 55

Reply

11
21 22
31 32 33
41 42 43 44
51 52 53 54 55

Reply

please solve this one:

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

Reply
This comment has been removed by the author.

1
2 1
3 2 1
4 3 2 1
i want logic for this patter please help me out

Reply

how to print this pattern
12345
2345
345
45
5

Reply

program for this pattern
12345
2345
345
45
5

Reply

1 2 3 4 5 6
1 2 3 4 5
1 2 3 4
1 2 3
1 2
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
1 2 3 4 5 6
code please

Reply

1
2 3
3 4 5
4 5 6 7
5 6 7 8 9
give me code for this

Reply

Check This Code

public class pattern
{


public static void main(String []args)
{

int i, j;

for(i=1;i<=5;i++)

{

for(j=i;j>=1;j--)

{

System.out.print(j%2);

}

System.out.println();

}

}

}

Reply

Please solve
Write a java program that asks user a character ch and a integer n and print a S pattern using n lines
output:
ch=@
n=6
@@@@@@
@
@@@@@@
@
@@@@@@

Reply

///0///
//010//
/01210/
//010//
///0///
Note : / represents space.

Reply

1
00
11 1
0000
…..
please help me.....

Reply

Hello, i want a java code for the below pattern
1
2 6
3 7 10
4 8 11 13
5 9 12 14

Reply

Sir please can you help me with the code for
1
1+2=3
1+2+3=6
Till
1+2+3+4+5+6+7+8+9+10=55
Your help is always appreciate, please make it asap, thank you.

Reply
This comment has been removed by the author.

import java.util.*;
public class pattern
{
public static void main(String args[])
{
int n,i,j;
Scanner sc=new Scanner(System.in);
System.out.println("Enter the size of the pattern");
n=sc.nextInt();
for(i=1;i<=n;i++)
{
for(j=1;j<=i;j++)
{
if(i%2==0)
System.out.print("0");
else
System.out.print("1");
}
System.out.println();
}
}
}


check this code for
1
00
111
0000

Reply

Check this code Divya.

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

Reply

Hello Vasavi !!!!
Try this code


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

Reply

Class abc {
Void display{
Int p =3 ;
For(int x=0; x<=2;x++){
For(int y=1;y<=p;y++){
System.out.print(" ");}
For(int z=0;z<=x;z++){
System.out.print(z);}
For(int i =2;i<=3-x;i--){
System.out.print(x-1);}
p=p-1;
System.out.println(" ");}
Int s= 2;
For(int n=1;n<=0;n--){
For(int m=1;m<=s;m++){
System.out.print(" ");}
For( int o =0;o<=n;o++){
System.out.print(o);}
For(int w = 2;w>=n;w--){
System.out.print(n-1);}
S++;
System.out.println(" ");}
}
}

Reply

public class pattern11 {
public static void main(String args[])
{
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

5
545
54345
5432345
543212345

Reply

Sir ? How to code this

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

Reply

Sir ? How to code this

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

Reply

Write a method called printNumbers that accepts a maximum number as a parameter and prints each number from 1 up to that maximum, inclusive, boxed by square brackets. For example, consider the following calls:

printNumbers(15);
printNumbers(5);
These calls should produce the following output:

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

Reply

123454321
1234 4321
123 321
12 12
1 1

Reply

How to do this pattern? Please rply as soon as possible:
1234321
123 321
12 21
1 1
12 21
123 321
1234321

Reply

Where are these pattern problems used when tackling real life programming situations, like while developing certain kind of application?

Reply

Can u help with me this???

123456789
--12345678
----1234567
------123456
--------12345
----------1234
------------123
--------------12

Reply
This comment has been removed by the author.

Hello! ma-wabeauty, here's the code you want:

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

for(int k=9-i ; k<8 ; k++){
System.out.print(" ");
}

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

System.out.println();
}

}
}

Reply

hi
if u could explain me use of int test,j,i in the prg

Reply

SIR PLEASE SOLVE THIS PROGRAM
write a program to generate afollowing pattern :
$
???
<<<<<
<<<<<<<
#########

Reply

Under recursive structure, a sum of a number X is equal to X+(X-1)+(X-2)+...+1.
Create a class called recursiveSum which will compute and print the sum of an integer on the screen

Reply

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

Reply

import java.util.Scanner;

public class Pattern28
{
public static void main(String[] args)
{
System.out.println("Enter the number of rows in Pattern");
Scanner scn = new Scanner(System.in);
int row_num = scn.nextInt();
for(int i = 1; i <= row_num; i++)
{
if((i % 2) != 0)
{
for(int j = 1; j <= 5; j++)
{
System.out.print(i);
}
System.out.print(i+1);
}
else
{
System.out.print(i+1);
for(int j = 1; j <= 5; j++)
{
System.out.print(i);
}
}
System.out.println();
}
}
}

Reply

import java.util.Scanner;

public class Pattern29
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
System.out.println("Enter the number of rows of pattern you want : ");
int row_num = sc.nextInt();
int patt_num = 1;
int inc = 3;
int first_inc = 1;
int second_inc = 0;
for(int i = 1; i <= row_num; i++)
{
if(i == patt_num)
{
for(int j = 1; j <= first_inc; j++)
{
System.out.print(j);
}
patt_num = patt_num + inc;
inc++;
first_inc = first_inc + 2;
second_inc = second_inc + 2;
}
else
{
for(int j = 1; j <= second_inc; j++)
{
System.out.print(j);
}
}
System.out.println();
}
}
}

Reply

can u pls help me solve these 2 programs using only 2 for loops....

1) 3
2 3 4
1 2 3 4 5

AND

2) 1 2 3 4 5
2 3 4
3

Reply

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

Reply

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

Reply

What will be the programme for this pattern:
_____1
____21
___321
__4321
_54321

Reply

select any three numbers between 0-9 and to find the probability pattern of that three numbers

for example:

if i selected as 123 then output will be as:

1 2 3
1 3 2
2 1 3
2 3 1
3 1 2
3 2 1

Reply

how to print given string in w format
p g m
r a
o r

Reply

Pls solve this pattern
2
4 6
8 10 12
14 16 18 20

Reply

can anyone help me for this pattern
12345
23456
34567
45678
56789

Reply

What will be the code for this pattern
1
121
12321
1234321

Reply
«Oldest   ‹Older   201 – 400 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.