Java number patterns program

Top 10 frequently asked Java number patterns program

Java number patterns program

Below are the number patterns for which we have written the java code.

Java number patterns program


Java number patterns program 1

To print the numbers in below manner:

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

Java Program:

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 to print?");
 
        int rows = sc.nextInt();
 
        System.out.println("Here is your output....!!!");
 
        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();
    }
}

OutPut:

How many rows you want to print?
5
Here is your output....!!!
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5

Java number patterns program 2

Program to print numbers in below manners

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

Java Program:

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 to print?");
 
        int rows = sc.nextInt();
 
        System.out.println("Here is your output ....!!!");
 
        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();
    }
}

Output:

How many rows you want to print?
5
Here is your output ....!!!
1
2 2
3 3 3
4 4 4 4
5 5 5 5 5

Java number patterns program 3

Program to print numbers in below manners

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

Java Program

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 to print?");
 
        int rows = sc.nextInt();
 
        System.out.println("Here is your output....!!!");
 
        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();
    }
}

Output:

How many rows you want to print?
5
Here is your output....!!!
5 4 3 2 1 
5 4 3 2 
5 4 3 
5 4
5



Java number patterns program 4

Program to print numbers in below manners

5
5 4
5 4 3 
5 4 3 2 
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 to print?");
 
        int rows = sc.nextInt();
 
        System.out.println("Here is your output....!!!");
 
        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();
    }
}

Output:

How many rows you want to print?
5
Here is your output....!!!
5
5 4
5 4 3 
5 4 3 2 
5 4 3 2 1

Java number patterns program 5

Program to print numbers in below manners

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

Java Program

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 to print?");
 
        int rows = sc.nextInt();
 
        System.out.println("Here is your output....!!!");
 
        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();
    }
}

Output:

How many rows you want to print?
5
Here is your output....!!!
5 4 3 2 1
4 3 2 1
3 2 1
2 1
1

Java number patterns program 6

Program to print numbers in below manners

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

Java Program:

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 numbers you want to print?");
 
        int rows = sc.nextInt();
 
        System.out.println("Here is your output....!!!");
 
        //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 &lt;= rows; i++) 
        {
            for (int j = 1; j &lt;= i; j++)
            {
                System.out.print(j+" ");
            }
 
            System.out.println();
        }
 
        //Closing the resources
 
        sc.close();
    }
}

Output

How many numbers you want to print?
5
Here is your output....!!!
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


Java number patterns program 7

Program to print numbers in below manners

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

Java Program

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();
    }
}

Output:

How many rows you want in this pattern?
5
Here is your pattern....!!!
1
2 1
3 2 1
4 3 2 1
5 4 3 2 1





Java number patterns program 8

Program to print numbers in below manners

1
1 0
1 0 1
1 0 1 0
1 0 1 0 1
. . . . . . . . . . . . . 

Java Program:

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&lt;= rows; i++) 
        {
            for (int j = 1; j&lt;= i; j++)
            {
                if(j%2 == 0)
                {
                    System.out.print(0);
                }
                else
                {
                    System.out.print(1);
                }
            }             
            System.out.println();
        }
 
        sc.close();
    }
}

Output

How many rows you want in this pattern?
5
Here is your pattern….!!!
1
10
101
1010
10101


Java number patterns program 9

Program to print numbers in below manners

00000..
01000..
00200..
00030..
00004..
. . . . . . . . .

Java Program

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 = 0; i< rows; i++) 
        {
            for (int j = 0; j< rows; j++)
            {
                if(i == j)
                {
                    System.out.print(i);
                }
                else
                {
                    System.out.print(0);
                }
            }
 
            System.out.println();
        }
 
        sc.close();
    }
}

Output:

How many rows you want in this pattern?
5
Here is your pattern….!!!
00000
01000
00200
00030
00004


Java number patterns program 10: Floyd’s Triangle

Program to print numbers in below manner

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

Java Program to Print Floyd’s Triangle

import java.util.Scanner;
 
public class FloydsTriangle 
{    
    public static void main(String[] args) 
    {
        System.out.println("How many rows you want in Floyd's Triangle?");
 
        Scanner sc = new Scanner(System.in);
 
        int noOfRows = sc.nextInt();
 
        int value = 1;
 
        System.out.println("Floyd's Triangle : ");
 
        for (int i = 1; i <= noOfRows; i++) 
        {
            for (int j = 1; j<= i; j++) 
            {
                System.out.print(value+"\t");
 
                value++;
            }
 
            System.out.println();
        }
    }    
}

Output:

How many rows you want in Floyd's Triangle?
5
Floyd's Triangle : 
1   
2    3   
4    5    6   
7    8    9    10   
11   12   13   14   15

Hope you like the article, subscribe and please share to keep updated with Techpursue.

One Reply to “Top 10 frequently asked Java number patterns program”

Leave a Reply