Explore Courses
Liverpool Business SchoolLiverpool Business SchoolMBA by Liverpool Business School
  • 18 Months
Bestseller
Golden Gate UniversityGolden Gate UniversityMBA (Master of Business Administration)
  • 15 Months
Popular
O.P.Jindal Global UniversityO.P.Jindal Global UniversityMaster of Business Administration (MBA)
  • 12 Months
New
Birla Institute of Management Technology Birla Institute of Management Technology Post Graduate Diploma in Management (BIMTECH)
  • 24 Months
Liverpool John Moores UniversityLiverpool John Moores UniversityMS in Data Science
  • 18 Months
Popular
IIIT BangaloreIIIT BangalorePost Graduate Programme in Data Science & AI (Executive)
  • 12 Months
Bestseller
Golden Gate UniversityGolden Gate UniversityDBA in Emerging Technologies with concentration in Generative AI
  • 3 Years
upGradupGradData Science Bootcamp with AI
  • 6 Months
New
University of MarylandIIIT BangalorePost Graduate Certificate in Data Science & AI (Executive)
  • 8-8.5 Months
upGradupGradData Science Bootcamp with AI
  • 6 months
Popular
upGrad KnowledgeHutupGrad KnowledgeHutData Engineer Bootcamp
  • Self-Paced
upGradupGradCertificate Course in Business Analytics & Consulting in association with PwC India
  • 06 Months
OP Jindal Global UniversityOP Jindal Global UniversityMaster of Design in User Experience Design
  • 12 Months
Popular
WoolfWoolfMaster of Science in Computer Science
  • 18 Months
New
Jindal Global UniversityJindal Global UniversityMaster of Design in User Experience
  • 12 Months
New
Rushford, GenevaRushford Business SchoolDBA Doctorate in Technology (Computer Science)
  • 36 Months
IIIT BangaloreIIIT BangaloreCloud Computing and DevOps Program (Executive)
  • 8 Months
New
upGrad KnowledgeHutupGrad KnowledgeHutAWS Solutions Architect Certification
  • 32 Hours
upGradupGradFull Stack Software Development Bootcamp
  • 6 Months
Popular
upGradupGradUI/UX Bootcamp
  • 3 Months
upGradupGradCloud Computing Bootcamp
  • 7.5 Months
Golden Gate University Golden Gate University Doctor of Business Administration in Digital Leadership
  • 36 Months
New
Jindal Global UniversityJindal Global UniversityMaster of Design in User Experience
  • 12 Months
New
Golden Gate University Golden Gate University Doctor of Business Administration (DBA)
  • 36 Months
Bestseller
Ecole Supérieure de Gestion et Commerce International ParisEcole Supérieure de Gestion et Commerce International ParisDoctorate of Business Administration (DBA)
  • 36 Months
Rushford, GenevaRushford Business SchoolDoctorate of Business Administration (DBA)
  • 36 Months
KnowledgeHut upGradKnowledgeHut upGradSAFe® 6.0 Certified ScrumMaster (SSM) Training
  • Self-Paced
KnowledgeHut upGradKnowledgeHut upGradPMP® certification
  • Self-Paced
IIM KozhikodeIIM KozhikodeProfessional Certification in HR Management and Analytics
  • 6 Months
Bestseller
Duke CEDuke CEPost Graduate Certificate in Product Management
  • 4-8 Months
Bestseller
upGrad KnowledgeHutupGrad KnowledgeHutLeading SAFe® 6.0 Certification
  • 16 Hours
Popular
upGrad KnowledgeHutupGrad KnowledgeHutCertified ScrumMaster®(CSM) Training
  • 16 Hours
Bestseller
PwCupGrad CampusCertification Program in Financial Modelling & Analysis in association with PwC India
  • 4 Months
upGrad KnowledgeHutupGrad KnowledgeHutSAFe® 6.0 POPM Certification
  • 16 Hours
O.P.Jindal Global UniversityO.P.Jindal Global UniversityMaster of Science in Artificial Intelligence and Data Science
  • 12 Months
Bestseller
Liverpool John Moores University Liverpool John Moores University MS in Machine Learning & AI
  • 18 Months
Popular
Golden Gate UniversityGolden Gate UniversityDBA in Emerging Technologies with concentration in Generative AI
  • 3 Years
IIIT BangaloreIIIT BangaloreExecutive Post Graduate Programme in Machine Learning & AI
  • 13 Months
Bestseller
IIITBIIITBExecutive Program in Generative AI for Leaders
  • 4 Months
upGradupGradAdvanced Certificate Program in GenerativeAI
  • 4 Months
New
IIIT BangaloreIIIT BangalorePost Graduate Certificate in Machine Learning & Deep Learning (Executive)
  • 8 Months
Bestseller
Jindal Global UniversityJindal Global UniversityMaster of Design in User Experience
  • 12 Months
New
Liverpool Business SchoolLiverpool Business SchoolMBA with Marketing Concentration
  • 18 Months
Bestseller
Golden Gate UniversityGolden Gate UniversityMBA with Marketing Concentration
  • 15 Months
Popular
MICAMICAAdvanced Certificate in Digital Marketing and Communication
  • 6 Months
Bestseller
MICAMICAAdvanced Certificate in Brand Communication Management
  • 5 Months
Popular
upGradupGradDigital Marketing Accelerator Program
  • 05 Months
Jindal Global Law SchoolJindal Global Law SchoolLL.M. in Corporate & Financial Law
  • 12 Months
Bestseller
Jindal Global Law SchoolJindal Global Law SchoolLL.M. in AI and Emerging Technologies (Blended Learning Program)
  • 12 Months
Jindal Global Law SchoolJindal Global Law SchoolLL.M. in Intellectual Property & Technology Law
  • 12 Months
Jindal Global Law SchoolJindal Global Law SchoolLL.M. in Dispute Resolution
  • 12 Months
upGradupGradContract Law Certificate Program
  • Self paced
New
ESGCI, ParisESGCI, ParisDoctorate of Business Administration (DBA) from ESGCI, Paris
  • 36 Months
Golden Gate University Golden Gate University Doctor of Business Administration From Golden Gate University, San Francisco
  • 36 Months
Rushford Business SchoolRushford Business SchoolDoctor of Business Administration from Rushford Business School, Switzerland)
  • 36 Months
Edgewood CollegeEdgewood CollegeDoctorate of Business Administration from Edgewood College
  • 24 Months
Golden Gate UniversityGolden Gate UniversityDBA in Emerging Technologies with Concentration in Generative AI
  • 36 Months
Golden Gate University Golden Gate University DBA in Digital Leadership from Golden Gate University, San Francisco
  • 36 Months
Liverpool Business SchoolLiverpool Business SchoolMBA by Liverpool Business School
  • 18 Months
Bestseller
Golden Gate UniversityGolden Gate UniversityMBA (Master of Business Administration)
  • 15 Months
Popular
O.P.Jindal Global UniversityO.P.Jindal Global UniversityMaster of Business Administration (MBA)
  • 12 Months
New
Deakin Business School and Institute of Management Technology, GhaziabadDeakin Business School and IMT, GhaziabadMBA (Master of Business Administration)
  • 12 Months
Liverpool John Moores UniversityLiverpool John Moores UniversityMS in Data Science
  • 18 Months
Bestseller
O.P.Jindal Global UniversityO.P.Jindal Global UniversityMaster of Science in Artificial Intelligence and Data Science
  • 12 Months
Bestseller
IIIT BangaloreIIIT BangalorePost Graduate Programme in Data Science (Executive)
  • 12 Months
Bestseller
O.P.Jindal Global UniversityO.P.Jindal Global UniversityO.P.Jindal Global University
  • 12 Months
WoolfWoolfMaster of Science in Computer Science
  • 18 Months
New
Liverpool John Moores University Liverpool John Moores University MS in Machine Learning & AI
  • 18 Months
Popular
Golden Gate UniversityGolden Gate UniversityDBA in Emerging Technologies with concentration in Generative AI
  • 3 Years
Rushford, GenevaRushford Business SchoolDoctorate of Business Administration (AI/ML)
  • 36 Months
Ecole Supérieure de Gestion et Commerce International ParisEcole Supérieure de Gestion et Commerce International ParisDBA Specialisation in AI & ML
  • 36 Months
Golden Gate University Golden Gate University Doctor of Business Administration (DBA)
  • 36 Months
Bestseller
Ecole Supérieure de Gestion et Commerce International ParisEcole Supérieure de Gestion et Commerce International ParisDoctorate of Business Administration (DBA)
  • 36 Months
Rushford, GenevaRushford Business SchoolDoctorate of Business Administration (DBA)
  • 36 Months
Liverpool Business SchoolLiverpool Business SchoolMBA with Marketing Concentration
  • 18 Months
Bestseller
Golden Gate UniversityGolden Gate UniversityMBA with Marketing Concentration
  • 15 Months
Popular
Jindal Global Law SchoolJindal Global Law SchoolLL.M. in Corporate & Financial Law
  • 12 Months
Bestseller
Jindal Global Law SchoolJindal Global Law SchoolLL.M. in Intellectual Property & Technology Law
  • 12 Months
Jindal Global Law SchoolJindal Global Law SchoolLL.M. in Dispute Resolution
  • 12 Months
IIITBIIITBExecutive Program in Generative AI for Leaders
  • 4 Months
New
IIIT BangaloreIIIT BangaloreExecutive Post Graduate Programme in Machine Learning & AI
  • 13 Months
Bestseller
upGradupGradData Science Bootcamp with AI
  • 6 Months
New
upGradupGradAdvanced Certificate Program in GenerativeAI
  • 4 Months
New
KnowledgeHut upGradKnowledgeHut upGradSAFe® 6.0 Certified ScrumMaster (SSM) Training
  • Self-Paced
upGrad KnowledgeHutupGrad KnowledgeHutCertified ScrumMaster®(CSM) Training
  • 16 Hours
upGrad KnowledgeHutupGrad KnowledgeHutLeading SAFe® 6.0 Certification
  • 16 Hours
KnowledgeHut upGradKnowledgeHut upGradPMP® certification
  • Self-Paced
upGrad KnowledgeHutupGrad KnowledgeHutAWS Solutions Architect Certification
  • 32 Hours
upGrad KnowledgeHutupGrad KnowledgeHutAzure Administrator Certification (AZ-104)
  • 24 Hours
KnowledgeHut upGradKnowledgeHut upGradAWS Cloud Practioner Essentials Certification
  • 1 Week
KnowledgeHut upGradKnowledgeHut upGradAzure Data Engineering Training (DP-203)
  • 1 Week
MICAMICAAdvanced Certificate in Digital Marketing and Communication
  • 6 Months
Bestseller
MICAMICAAdvanced Certificate in Brand Communication Management
  • 5 Months
Popular
IIM KozhikodeIIM KozhikodeProfessional Certification in HR Management and Analytics
  • 6 Months
Bestseller
Duke CEDuke CEPost Graduate Certificate in Product Management
  • 4-8 Months
Bestseller
Loyola Institute of Business Administration (LIBA)Loyola Institute of Business Administration (LIBA)Executive PG Programme in Human Resource Management
  • 11 Months
Popular
Goa Institute of ManagementGoa Institute of ManagementExecutive PG Program in Healthcare Management
  • 11 Months
IMT GhaziabadIMT GhaziabadAdvanced General Management Program
  • 11 Months
Golden Gate UniversityGolden Gate UniversityProfessional Certificate in Global Business Management
  • 6-8 Months
upGradupGradContract Law Certificate Program
  • Self paced
New
IU, GermanyIU, GermanyMaster of Business Administration (90 ECTS)
  • 18 Months
Bestseller
IU, GermanyIU, GermanyMaster in International Management (120 ECTS)
  • 24 Months
Popular
IU, GermanyIU, GermanyB.Sc. Computer Science (180 ECTS)
  • 36 Months
Clark UniversityClark UniversityMaster of Business Administration
  • 23 Months
New
Golden Gate UniversityGolden Gate UniversityMaster of Business Administration
  • 20 Months
Clark University, USClark University, USMS in Project Management
  • 20 Months
New
Edgewood CollegeEdgewood CollegeMaster of Business Administration
  • 23 Months
The American Business SchoolThe American Business SchoolMBA with specialization
  • 23 Months
New
Aivancity ParisAivancity ParisMSc Artificial Intelligence Engineering
  • 24 Months
Aivancity ParisAivancity ParisMSc Data Engineering
  • 24 Months
The American Business SchoolThe American Business SchoolMBA with specialization
  • 23 Months
New
Aivancity ParisAivancity ParisMSc Artificial Intelligence Engineering
  • 24 Months
Aivancity ParisAivancity ParisMSc Data Engineering
  • 24 Months
upGradupGradData Science Bootcamp with AI
  • 6 Months
Popular
upGrad KnowledgeHutupGrad KnowledgeHutData Engineer Bootcamp
  • Self-Paced
upGradupGradFull Stack Software Development Bootcamp
  • 6 Months
Bestseller
KnowledgeHut upGradKnowledgeHut upGradBackend Development Bootcamp
  • Self-Paced
upGradupGradUI/UX Bootcamp
  • 3 Months
upGradupGradCloud Computing Bootcamp
  • 7.5 Months
PwCupGrad CampusCertification Program in Financial Modelling & Analysis in association with PwC India
  • 5 Months
upGrad KnowledgeHutupGrad KnowledgeHutSAFe® 6.0 POPM Certification
  • 16 Hours
upGradupGradDigital Marketing Accelerator Program
  • 05 Months
upGradupGradAdvanced Certificate Program in GenerativeAI
  • 4 Months
New
upGradupGradData Science Bootcamp with AI
  • 6 Months
Popular
upGradupGradFull Stack Software Development Bootcamp
  • 6 Months
Bestseller
upGradupGradUI/UX Bootcamp
  • 3 Months
PwCupGrad CampusCertification Program in Financial Modelling & Analysis in association with PwC India
  • 4 Months
upGradupGradCertificate Course in Business Analytics & Consulting in association with PwC India
  • 06 Months
upGradupGradDigital Marketing Accelerator Program
  • 05 Months

Top 12 Pattern Programs in Java You Should Checkout Today

Updated on 22 November, 2022

21K+ views
12 min read

Preparing for technical interviews is tricky, and if you’re a Java professional, things are more complicated. A popular method of analyzing a Java professional’s expertise is by seeing how well one can make a pattern program in Java. You might have to make a unique Java pattern program, which is not prevalent to nail the interview.

Don’t worry because, in this article, we’ll take a look at multiple Java patterns so you can get a better understanding of the same. The article will also highlight some of the popular design patterns in Java, such as singleton design patterns, and factory design patterns, among others. 

All of the patterns we’ve discussed here are made of digits. The best way to practice these patterns would be to try to create the first and if you struggle at some point, compare your code with ours. This way, you’ll understand what does what and would not have any confusion regarding these programs.

Check out our free courses to get an edge over the competition.

We recommend working your way up from the first pattern. If you have some experience creating a Java pattern program, you can start with any of the designs we’ve shared below:

Read: Java Developer Salary in India

Check out upGrad: Java Bootcamp

What is pattern printing in Java?

Before we delve into the various design patterns in Java, let’s take a look at what exactly pattern printing in Java refers to. To put it simply, pattern printing programs are patterns or symbols that contain alphabets, or characters in a particular form. These programs mainly aim to improve logic, coding skills, and looping concepts. A Java pattern program specifically can be printed in various designs.

Simple Triangle Pattern

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

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

    }

}

Check out upGrad: Advanced Certification in Blockchain

Double Triangle Pattern

Pattern:

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

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

    }

}

Learn more: Top 8 Java Projects on Github You Should Get Your Hands-on
 

upGrad’s Exclusive Software and Tech Webinar for you –

SAAS Business – What is So Different?

Triangle Pattern with Repeated Digits

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 

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

    }

}

Inverted Triangle with Descending Digits

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

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

    }

}

Triangle with Repeating Pattern

Pattern:

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

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

    }

}

Double Triangle Pattern

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

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

    }

}

Inverted Double Triangles

Pattern:

1234567

  234567

    34567

      4567

        567

          67

            7

          67

        567

      4567

    34567

  234567

1234567

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

    }

}

Double Inverted Triangles

Pattern:

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

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

    }

}

Digit Pillar Pattern

Pattern:

1111111

1111122

1111333

1114444

1155555

1666666

7777777 

Code:

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

    }

}

Binary Digit Pattern

Pattern:

1010101

0101010

1010101

0101010

1010101

0101010

1010101

Code:

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

    }

}

Ascending Triangle Pattern

Pattern:

1

2 6

3 7 10 

4 8 11 13

5 9 12 14 15

Code:

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

    }

}

Square Java Pattern Program

Pattern:

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 

Code:

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

    }

}

Also Read: Python vs Java in 2020: Which One You Should Choose?

Star Pattern In Java

Star pattern is considered to be one of the most common design pattern programs in Java, which is mainly used to improve logical thinking, as well as flow control knowledge. In order to display star patterns in Java, two to three loops are generally required, depending on the programs. The first loop of the star pattern in Java is also sometimes referred to as the outer loop, whereas the second loop is the inner one, which contains rows and columns. 

Factory Design Pattern In Java

Factory Design pattern in Java is yet another fundamental method used in Java. It is mainly used when there are multiple sub-classes with a superclass, and you need to return one of the sub-classes based on the input. This method successfully eliminates the responsibility of the instantiation of a classroom the client program to the factory class. There are a ton of advantages that you can derive from implementing factory design patterns in Java. Some of them might include, with factory design patterns, codes getting more robust and easy to extend. Furthermore, factory design pattern also allows abstraction between implementation and client classes. 

Singleton Design Pattern Java

There are mainly two types of singleton design pattern Java has, namely, early instantiation and lazy instantiation. In this design pattern, a class ensures that only one instance has been created, which can then be used by all the other classes. One of the top advantages of using the Singleton Design Pattern in Java is that you save a lot of memory since only one instance is used every time by all the other classes.

Final Thoughts

We are sure that you’re ready to create a pattern program in Java after going through this list. You can start with any pattern according to your experience and expertise. If you have any questions regarding this topic or this article, please let us know in the comment section below.

If you’re interested to learn more about Java, full-stack software development, check out upGrad & IIIT-B’s PG Diploma in Full-stack Software Development which is designed for working professionals and offers 500+ hours of rigorous training, 9+ projects, and assignments, IIIT-B Alumni status, practical hands-on capstone projects & job assistance with top firms.

Frequently Asked Questions (FAQs)

1. What is the scope of Java?

Java professionals have a bright future in India. Although it originates from C and C++, it is an object-oriented programming language with a simpler object model. It offers a virtual machine, known as the JVM, that is loaded with bytecode and can run on any system. As a result, pursuing a profession in the field of Java is both prudent and profitable. Java is expected to remain the first choice for most enterprises because of its robust community, enterprise support, and growing popularity among programmers. As a result, java job prospects are not moving away anytime soon. Java is a strongly typed language of programming used for web designing, Android development, enterprise-class applications, and the Internet of Things (IoT).

2. What is the average salary of Java developers?

Web-based apps are created by Java developers. Java developers have to adjust the design and functioning of websites according to their clients' requests using the Java scripting language. Java Developers make an average of ₹4,82,846 per year. An entry-level Java Developer with less than a year of experience may expect to make a total salary of ₹2,94,582, which includes tips, bonuses, and overtime pay. The average total income for an early-career Java Developer with 1-4 years of experience is ₹4,45,758. The average total salary of ₹8,94,717 is earned by a Java Developer in their mid-career, with 5-9 years of experience. The average total compensation for an experienced Java Developer with 10-19 years of experience is ₹13,65,056.

3. What is JVM?

The JVM, which is also known as Java Virtual Machine, is a run-time engine that allows Java applications to run. JVM is the program that compiles the main method in java programming. It is a component of JRE or the Java Runtime Environment. Java programs follow the principle of WORA (Write Once Run Anywhere). Through this method, a programmer can write Java code on one system, and this code can operate without modification on any other Java-enabled device. This is feasible because of JVM. Java code is first compiled into bytecode. On different machines, this bytecode is interpreted. Bytecode serves as a bridge between the host system and the Java source code. The Java Virtual Machine is responsible for memory allocation.

RELATED PROGRAMS