How To Print Different Number Pattern Programs In Java

Pattern No. 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

Java Code :-

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 Do You Want In This Pattern ?");
        
        int rows = sc.nextInt();
        
        System.out.println("Here's 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();
    }
}

Output :

How Many Rows  Do You Want In This Pattern ?
7
Here’s your pattern !
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

Pattern No. 2

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

Java Code :-

importjava.util.Scanner;
publicclassMainClass
{
    publicstaticvoidmain(String[] args)
    {
        Scanner sc = newScanner(System.in);
        
        //Taking rows value from the user
        
        System.out.println("How Many Rows  Do You Want In This Pattern ?");
        
        introws = sc.nextInt();
        
        System.out.println("Here's your pattern !");
        
        for(inti = 1; i <= rows; i++)
        {
            for(intj = 1; j <= i; j++)
            {
                System.out.print(i+" ");
            }
            
            System.out.println();
        }
        
        //Close the resources
        
        sc.close();
    }
}

Output :

How Many Rows  Do You Want In This Pattern ?
7
Here’s your pattern !
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

 Pattern No. 3
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
1 2 3 4 5 6
1 2 3 4 5
1 2 3 4
1 2 3
1 2
1
Java Code :-
importjava.util.Scanner;
publicclassMainClass
{
    publicstaticvoidmain(String[] args)
    {
        Scanner sc = newScanner(System.in);
        
        //Taking rows value from the user
        
        System.out.println("How Many Rows  Do You Want In This Pattern ?");
        
        introws = sc.nextInt();
        
        System.out.println("Here's your pattern !");
        
        //Printing upper half of the pattern
        
        for(inti = 1; i <= rows; i++)
        {
            for(intj = 1; j <= i; j++)
            {
                System.out.print(j+" ");
            }
            
            System.out.println();
        }
        
        //Printing lower half of the pattern
        
        for(inti = rows-1; i >= 1; i--)
        {
            for(intj = 1; j <= i; j++)
            {
                System.out.print(j+" ");
            }
            
            System.out.println();
        }
        
        //Closing the resources
        
        sc.close();
    }
}

Output :

How Many Rows Do You Want In This Pattern ?
7
Here’s your pattern !
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
1 2 3 4 5 6
1 2 3 4 5
1 2 3 4
1 2 3
1 2
1

Pattern No.4

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

Java Code :-

importjava.util.Scanner;
publicclassMainClass
{
    publicstaticvoidmain(String[] args)
    {
        Scanner sc = newScanner(System.in);
        
        //Taking rows value from the user
        
        System.out.println("How many rows you want in this pattern?");
        
        introws = sc.nextInt();
        
        System.out.println("Here is your pattern....!!!");
        
        for(inti = rows; i >= 1; i--)
        {
            for(intj = 1; j <= i; j++)
            {
                System.out.print(j+" ");
            }
            
            System.out.println();
        }
        
        //Closing the resources
        
        sc.close();
    }
}

Output :

How Many Rows Do You Want In This Pattern ?
7
Here’s your pattern !

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

Pattern No. 5

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

Java Code :-

importjava.util.Scanner;
publicclassMainClass
{
    publicstaticvoidmain(String[] args)
    {
        Scanner sc = newScanner(System.in);
        
        //Taking rows value from the user
        
        System.out.println("How many rows you want in this pattern?");
        
        introws = sc.nextInt();
        
        System.out.println("Here is your pattern....!!!");
        
        for(inti = 1; i <= rows; i++)
        {
            for(intj = rows; j >= i; j--)
            {
                System.out.print(j+" ");
            }
            
            System.out.println();
        }
        
        //Closing the resources
        
        sc.close();
    }
}

Output :

How Many Rows Do You Want In This Pattern ?
7
Here’s your pattern !

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

Pattern No. 6

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

Java Code :-

importjava.util.Scanner;
publicclassMainClass
{
    publicstaticvoidmain(String[] args)
    {
        Scanner sc = newScanner(System.in);
        
        //Taking rows value from the user
        
        System.out.println("How many rows you want in this pattern?");
        
        introws = sc.nextInt();
        
        System.out.println("Here is your pattern....!!!");
        
        for(inti = rows; i >= 1; i--)
        {
            for(intj = rows; j >= i; j--)
            {
                System.out.print(j+" ");
            }
            
            System.out.println();
        }
        
        //Closing the resources
        
        sc.close();
    }
}

Output :

How Many Rows Do You Want In This Pattern ?
7
Here’s your pattern !

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

Pattern No. 7

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

Java Code :-

importjava.util.Scanner;
publicclassMainClass
{
    publicstaticvoidmain(String[] args)
    {
        Scanner sc = newScanner(System.in);
        
        //Taking rows value from the user
        
        System.out.println("How many rows you want in this pattern?");
        
        introws = sc.nextInt();
        
        System.out.println("Here is your pattern....!!!");
        
        //Printing upper half of the pattern
        
        for(inti = rows; i >= 1; i--)
        {
            for(intj = 1; j <= i; j++)
            {
                System.out.print(j+" ");
            }
            
            System.out.println();
        }
        
        //Printing lower half of the pattern
        
        for(inti = 2; i <= rows; i++)
        {
            for(intj = 1; j <= i; j++)
            {
                System.out.print(j+" ");
            }
            
            System.out.println();
        }
        
        //Closing the resources
        
        sc.close();
    }
}

Output :

How Many Rows Do You Want In This Pattern ?
7
Here’s your pattern !

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

Pattern No. 7

1010101
0101010
1010101
0101010
1010101
0101010
1010101

Java Code :-

importjava.util.Scanner;
publicclassMainClass
{
    publicstaticvoidmain(String[] args)
    {
        Scanner sc = newScanner(System.in);
        
        System.out.println("How many rows you want in this pattern?");
        
        introws = sc.nextInt();
        
        System.out.println("Here is your pattern....!!!");
        
        for(inti = 1; i <= rows; i++)
        {
            intnum;
            
            if(i%2== 0)
            {
                num = 0;
                
                for(intj = 1; j <= rows; j++)
                {
                    System.out.print(num);
                    
                    num = (num == 0)? 1: 0;
                }
            }
            else
            {
                num = 1;
                
                for(intj = 1; j <= rows; j++)
                {
                    System.out.print(num);
                    
                    num = (num == 0)? 1: 0;
                }
            }
            
            System.out.println();
        }
        
        sc.close();
    }
}

Output :

How Many Rows Do You Want In This Pattern ?
7
Here’s your pattern !

1010101
0101010
1010101
0101010
1010101
0101010
1010101

 

Author: Fabian Ros
0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments