Add

Top 20 Different Number Pattern Programs In Java 2021

                  

Java programs to print the numbers or any different pattern is one of the easiest ways to kick off your coding skills in java. In this post I have taken some different number pattern programs in java and tried to solve them . Please add more pattern and their code in the comment sections.


Read Also : Alphabet pattern programs
                    Star Pattern Programs


Pattern programs in java : Pattern 1

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

import java.util.Scanner;

public class MainClass
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);

//Taking rows value from the user

System.out.println("How many rows you want in this pattern?");

int rows = sc.nextInt();

System.out.println("Here is your pattern....!!!");

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

System.out.println();
}

//Close the resources

sc.close();
}
}



Pattern programs in java : Pattern 2

1

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

import java.util.Scanner;

public class MainClass
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);

//Taking rows value from the user

System.out.println("How many rows you want in this pattern?");

int rows = sc.nextInt();

System.out.println("Here is your pattern....!!!");

//Printing upper half of the pattern

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

System.out.println();
}

//Printing lower half of the pattern

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

System.out.println();
}

//Closing the resources

sc.close();
}
}

Pattern programs in java : Pattern 3 

1

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

import java.util.Scanner;

public class MainClass
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);

//Taking rows value from the user

System.out.println("How many rows you want in this pattern?");

int rows = sc.nextInt();

System.out.println("Here is your pattern....!!!");

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

System.out.println();
}

//Close the resources

sc.close();
}
}


Pattern programs in java : Pattern 4

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


import java.util.Scanner;

public class MainClass
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);

//Taking rows value from the user

System.out.println("How many rows you want in this pattern?");

int rows = sc.nextInt();

System.out.println("Here is your pattern....!!!");

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

System.out.println();
}

//Closing the resources

sc.close();
}
}

Pattern programs in java : Pattern 5

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


import java.util.Scanner;

public class MainClass
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);

//Taking rows value from the user

System.out.println("How many rows you want in this pattern?");

int rows = sc.nextInt();

System.out.println("Here is your pattern....!!!");

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

System.out.println();
}

//Closing the resources

sc.close();
}
}

Pattern programs in java : Pattern 6

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


import java.util.Scanner;

public class MainClass
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);

//Taking rows value from the user

System.out.println("How many rows you want in this pattern?");

int rows = sc.nextInt();

System.out.println("Here is your pattern....!!!");

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

System.out.println();
}

//Closing the resources

sc.close();
}
}

Pattern programs in java : Pattern 7

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


import java.util.Scanner;

public class MainClass
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);

//Taking rows value from the user

System.out.println("How many rows you want in this pattern?");

int rows = sc.nextInt();

System.out.println("Here is your pattern....!!!");

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

System.out.println();
}

//Closing the resources

sc.close();
}
}

Pattern programs in java : Pattern 8

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
1 2 3 4 5 6 5 4 3 2 1
1 2 3 4 5 6 7 6 5 4 3 2 1

import java.util.Scanner;

public class MainClass
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);

//Taking rows value from the user

System.out.println("How many rows you want in this pattern?");

int rows = sc.nextInt();

System.out.println("Here is your pattern....!!!");

for (int i = 1; i <= rows; i++)
{
//Printing first half of the row

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

//Printing second half of the row

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

System.out.println();
}

//Closing the resources

sc.close();
}
}

Pattern programs in java : Pattern 9

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

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


import java.util.Scanner;

public class MainClass
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);

//Taking rows value from the user

System.out.println("How many rows you want in this pattern?");

int rows = sc.nextInt();

System.out.println("Here is your pattern....!!!");

//Printing upper half of the pattern

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

System.out.println();
}

//Printing lower half of the pattern

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

System.out.println();
}

//Closing the resources

sc.close();
}
}

Pattern programs in java : Pattern 10

1234567
  234567
    34567
      4567
        567
          67
            7
          67
        567
      4567
    34567
  234567
1234567





import java.util.Scanner;

public class MainClass
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);

//Taking rows value from the user

System.out.println("How many rows you want in this pattern?");

int rows = sc.nextInt();

System.out.println("Here is your pattern....!!!");

//Printing upper half of the pattern

for (int i = 1; i <= rows; i++)
{
//Printing i spaces at the beginning of each row

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

//Printing i to rows value at the end of each row

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

System.out.println();
}

//Printing lower half of the pattern

for (int i = rows-1; i >= 1; i--)
{
//Printing i spaces at the beginning of each row

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

//Printing i to rows value at the end of each row

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

System.out.println();
}

//Closing the resources

sc.close();
}
}

Pattern programs in java : Pattern 11

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


import java.util.Scanner;

public class MainClass
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);

//Taking rows value from the user

System.out.println("How many rows you want in this pattern?");

int rows = sc.nextInt();

System.out.println("Here is your pattern....!!!");

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

System.out.println();
}

//Close the resources

sc.close();
}
}

Pattern programs in java : Pattern 12

1
10
101
1010
10101
101010 
1010101


import java.util.Scanner;

public class MainClass
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);

System.out.println("How many rows you want in this pattern?");

int rows = sc.nextInt();

System.out.println("Here is your pattern....!!!");

for (int i = 1; i <= rows; i++)
{
for (int j = 1; j <= i; j++)
{
if(j%2 == 0)
{
System.out.print(0);
}
else
{
System.out.print(1);
}
}

System.out.println();
}

sc.close();
}
}


Pattern programs in java : Pattern 13

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


import java.util.Scanner;

public class MainClass
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);

//Taking rows value from the user

System.out.println("How many rows you want in this pattern?");

int rows = sc.nextInt();

System.out.println("Here is your pattern....!!!");

//Printing upper half of the pattern

for (int i = 1; i <= rows; i++)
{
//Printing i spaces at the beginning of each row

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

//Printing i to rows value at the end of each row

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

System.out.println();
}

//Printing lower half of the pattern

for (int i = rows-1; i >= 1; i--)
{
//Printing i spaces at the beginning of each row

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

//Printing i to rows value at the end of each row

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

System.out.println();
}

//Closing the resources

sc.close();
}
}

Pattern programs in java : Pattern 14

1111111
1111122
1111333
1114444
1155555
1666666
7777777 


import java.util.Scanner;

public class MainClass
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);

System.out.println("How many rows you want in this pattern?");

int rows = sc.nextInt();

System.out.println("Here is your pattern....!!!");

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

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

System.out.println();
}

sc.close();
}
}

Pattern programs in java : Pattern 15 

1010101
0101010
1010101
0101010
1010101
0101010
1010101


import java.util.Scanner;

public class MainClass
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);

System.out.println("How many rows you want in this pattern?");

int rows = sc.nextInt();

System.out.println("Here is your pattern....!!!");

for (int i = 1; i <= rows; i++)
{
int num;

if(i%2 == 0)
{
num = 0;

for (int j = 1; j <= rows; j++)
{
System.out.print(num);

num = (num == 0)? 1 : 0;
}
}
else
{
num = 1;

for (int j = 1; j <= rows; j++)
{
System.out.print(num);

num = (num == 0)? 1 : 0;
}
}

System.out.println();
}

sc.close();
}
}


Pattern programs in java : Pattern 16

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


import java.util.Scanner;

public class MainClass
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);

System.out.println("How many rows you want in this pattern?");

int rows = sc.nextInt();

System.out.println("Here is your pattern....!!!");

for (int i = 1; i <= rows; i++)
{
int num = i;

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

num = num+rows-j;
}

System.out.println();
}

sc.close();
}
}

 
Pattern programs in java : Pattern 17

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



import java.util.Scanner;

public class MainClass
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);

System.out.println("How many rows you want in this pattern?");

int rows = sc.nextInt();

System.out.println("Here is your pattern....!!!");

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

sc.close();
}
}


Pattern programs in java : Pattern 18

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


import java.util.Scanner;

public class MainClass
{
public static void main(String[] args)
{
System.out.println("How many rows you want in this pattern?");

Scanner sc = new Scanner(System.in);

int noOfRows = sc.nextInt();

int value = 1;

System.out.println("Here is your pattern :");

for (int i = 1; i <= noOfRows; i++)
{
for (int j = 1; j <= i; j++)
{
System.out.print(value+"\t");

value++;
}

System.out.println();
}
}
}

Pattern programs in java : Pattern 19

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


import java.util.Scanner;

public class MainClass
{
public static void main(String[] args)
{
System.out.println("How many rows you want in this pattern");

Scanner sc = new Scanner(System.in);

int noOfRows = sc.nextInt();

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

System.out.println();
}
}
}

Pattern programs in java : Pattern 20

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

import java.util.Scanner;

public class MainClass
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);

//Taking rows value from the user

System.out.println("How many rows you want in this pattern?");

int rows = sc.nextInt();

System.out.println("Here is your pattern....!!!");
for(int i=1 ; i <= rows ; i++)
{
System.out.print(i + " ");
int n = i;
for(int j = 1; j < i ; j++)
{
if(j%2 != 0)
{
System.out.print((n + ((2 * (rows + 1 - i)) - 1)) + " ");
n = n + ((2 * (rows + 1 - i)) - 1);
}
else
{
System.out.print((n + 2 * (i - j)) + " ");
n = n + 2 * (i - j);
}
}
System.out.println();
}


//Close the resources

sc.close();
}
}

Post a Comment

0 Comments
* Please Don't Spam Here. All the Comments are Reviewed by Admin.