Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

20 Different Number Pattern Programs in Java

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--)


This post first appeared on Java Hungry, please read the originial post: here

Share the post

20 Different Number Pattern Programs in Java

×

Subscribe to Java Hungry

Get updates delivered right to your inbox!

Thank you for your subscription

×