• Chennai, Bangalore & Online: 93450 45466Coimbatore: 95978 88270Madurai: 97900 94102

  • JAVA Pattern Programs



    Pattern Programs in JAVA can enhance your programming and logical skills using loops. Here we will learn some of these patterns under 3 categories:
    Star Pattern Programs with Java
    Numeric Pattern Programs with Java
    Character Pattern Programs with Java
    So let’s start with the star pattern programs

    Star Pattern Programs In With Java

    Java program for printing Right Half pyramid or Right Triangle
    import java.util.Scanner;   public class RightHalfPyramid{   public static void main(String[] args) { System.out.println(“Enter the number of rows for pattern: “); Scanner sc = new Scanner(System.in);  // taking the input with scanner int rows = sc.nextInt();   for(int row = 1; row <= rows; ++row) { for(int col = 1; col <= row; ++col) { System.out.print(“* “); } System.out.println(); } sc.close(); } }
    Output for the above program
    Enter the number of rows for pattern: 5 * *  * * *  * * * *  * * * * *
    Java program for printing Left Half pyramid or Left Triangle
    import java.util.Scanner;   public class LeftHalfPyramid { public static void main(String[] args) {   System.out.println(“Enter the number of rows for pattern: “); Scanner sc = new Scanner(System.in);  // taking the input with scanner int rows = sc.nextInt();   for (int row=1; row<=rows; row++) { // Printing space in decreasing order for (int col=rows; col>row; col–) { System.out.print(” “); } // Printing star in increasing order for (int star=1; star<=row; star++) { System.out.print(“*”); } System.out.println(); } sc.close(); } }
    Output for the above program
    Enter the number of rows for pattern: 5     *    **   ***  **** *****
    Java program for printing Full Pyramid or Triangle
    import java.util.Scanner;   public class FullPyramid { public static void main(String[] args) {   System.out.println(“Enter the number of rows for pattern: “); Scanner sc = new Scanner(System.in);  // taking the input with scanner int rows = sc.nextInt();   for (int row=1; row<=rows; row++) { // Print space in decreasing order for (int col=rows; col>row; col–) { System.out.print(” “); } // Print star in increasing order for (int star=1; star<=row; star++) { System.out.print(“* “); } System.out.println(); } sc.close(); } }
    Output for the above program
    Enter the number of rows for pattern: 5     *     * *    * * *   * * * *  * * * * *
    Java program for printing Rightly Inverted Half Pyramid or Downward Right Half Triangle
    import java.util.Scanner;   public class InvertedHalfPyramid {   public static void main(String[] args) {   System.out.println(“Enter the number of rows for pattern: “); Scanner sc = new Scanner(System.in);  // taking the input with scanner int rows = sc.nextInt();   for(int row = rows; row >= 1; –row) { for(int col = 1; col <= row; ++col) { System.out.print(” * “); } System.out.println(); } sc.close(); } }
    Output for the above program
    Enter the number of rows for pattern: 5   *  *  *  *  *   *  *  *  *   *  *  *   *  *   *
    Java program for printing Left Inverted Half Pyramid or Downward Left Half Triangle
    import java.util.Scanner; public class InvertedHalfPyramid {   public static void main(String[] args) { System.out.println(“Enter the number of rows for pattern: “); Scanner sc = new Scanner(System.in);  // taking the input with scanner int rows = sc.nextInt(); for (int row= rows; row>= 1; row–) { for (int col=rows; col>row;col–) { System.out.print(” “); } for (int count=1;count<=row;count++) { System.out.print(“*”); } System.out.println(“”); } sc.close();   } }

    Check out this Complete Online Java Course by FITA. FITA provides a complete Java course including core java and advanced java J2EE, and SOA training, where you will be building real time applications using Servlets, Hibernate Framework, and Spring with Aspect-Oriented Programming (AOP) architecture, Struts through JDBC bundled with, placement support, and certification at an affordable price with an active placement cell, to make you an industry required certified java developer.

    Output for the above program

    Enter the number of rows for pattern: 5 *****  ****   ***    **     *
    Java program for printing Inverted full pyramid or inverted triangle
    import java.util.Scanner; public class InvertedFullPyramid {   public static void main(String[] args) { System.out.println(“Enter the number of rows for pattern: “); Scanner sc = new Scanner(System.in);  // taking the input with scanner int rows = sc.nextInt(); for (int row= rows; row>= 1; row–) { for (int col=rows; col>row;col–) { System.out.print(” “); } for (int count=1;count<=row;count++) { System.out.print(” *”); } System.out.println(“”); } sc.close();   } }
    Output for the above program
    Enter the number of rows for pattern: 5  * * * * *   * * * *    * * *     * *      *
    Java Program for printing Diamond Pattern with stars
    import java.util.Scanner;   public class Diamond { public static void main(String[] args) { // Scanner object Scanner scanner = new Scanner(System.in);   // taking the number of rows with the scanner System.out.println(“Enter the number of rows for pattern: “);   int rows = scanner.nextInt();   for (int row=1; row<=rows; row++) { // Print space in decreasing order for (int col=rows; col>row; col–) { System.out.print(” “); } // Print star in increasing order for (int count=1; count<=(row * 2) -1; count++) { System.out.print(“*”); } System.out.println(); } for (int row=rows-1; row>=1; row–) { // Printing space in increasing order for (int col=rows-1; col>=row; col–) { System.out.print(” “); } // Printing stars in decreasing order for (int count=1; count<=(row * 2) -1; count++) { System.out.print(“*”); }   System.out.println(); } scanner.close(); } }
    Output for the above program
    Enter the number of rows for pattern: 5     *    ***   *****  ******* *********  *******   *****    ***      *
    Java Program for printing Sand Glass with Stars
    import java.util.Scanner;   public class SandGlass { public static void main(String[] args) { // scanner object Scanner sc = new Scanner(System.in); System.out.println(“Enter the number of rows for pattern: “); // taking the number of rows with scanner int rows = sc.nextInt(); for (int row = 0; row <= rows – 1; row++) { for (int col = 0; col < row; col++) { System.out.print(” “); } for (int count = row; count <= rows – 1; count++) { System.out.print(“* “); } System.out.println(“”); } for (int row = rows – 1; row >= 0; row–) { for (int col = 0; col < row; col++) { System.out.print(” “); } for (int count = row; count <= rows – 1; count++) { System.out.print(“* “); } System.out.println(“”); } sc.close(); } }
    Output for the above program
    Enter the number of rows for pattern: 5 * * * * *   * * * *    * * *     * *      *      *     * *    * * *   * * * *  * * * * * 

    Check out this Complete Online Java Training by FITA. FITA provides a complete core and advanced Java course where you will be building real-time applications using J2EE, Servlets, Hibernate Framework, and Spring with Aspect-Oriented Programming (AOP) architecture, Struts through JDBC bundled with, placement support, and certification at an affordable price with an active placement cell, to make you an industry-certified java developer.

    After the star pattern programs, we will now see the numeric pattern programs in java

    Numeric Pattern Programs With Java

    Java program to print simple numbered triangle pattern
    import java.util.Scanner;   public class Main { public static void main(String[] args) { // scanner object Scanner sc = new Scanner(System.in); System.out.println(“Enter the number of rows for pattern: “); int n = sc.nextInt(); // taking input with scanner sc int row, col,number;   for(row=0; row<n; row++) // outer loop for rows { number=1; for(col=0; col<=row; col++) // inner loop for rows { // adding a space after number System.out.print(number+ ” “);   //incrementing value of number number++; } // printing an empty line System.out.println(); } }   }
    Output for the above program
    Enter the number of rows for pattern:  5 1 2  1 2 3  1 2 3 4  1 2 3 4 5
    Java Program to print Floyd’s triangle pattern
    import java.io.*; import java.util.Scanner;   public class NumberPattern { public static void printNums(int num) { // initialising starting number int row, col, number = 1;   for (row = 0; row < num; row++) { for (col = 0; col <= row; col++) { // // adding a space after number System.out.print(number + ” “);   // incrementing number at every column number = number + 1; }   // ending line after each row System.out.println(); } }   public static void main(String args[]) { // scanner object Scanner sc = new Scanner(System.in); System.out.println(“Enter the number of rows for pattern: “); int num = sc.nextInt(); // taking input with scanner sc printNums(num); sc.close(); } }
    Output for the above program
    Enter the number of rows for pattern: 6 2 3  4 5 6  7 8 9 10  11 12 13 14 15  16 17 18 19 20 21
    Java Program for printing Pascal’s triangle Pattern
    import java.io.*; import java.util.Scanner; public class PascalPattern {   public static void main(String[] args) { //scanner object Scanner sc = new Scanner(System.in); System.out.println(“Enter the number of rows pattern: “); // taking input with scanner int rows = sc.nextInt(); int number = 1;   for(int row = 0; row < rows; row++) { for(int space = 1; space < rows – row; ++space) { System.out.print(”  “); }   for(int col = 0; col <= row; col++) { if (col == 0 || row == 0) number = 1; else number = number * (row – col + 1) / col;   System.out.printf(“%4d”, number); } // printing new line after iterations System.out.println(); } } }
    Output for the above program
    Enter the number of rows for pattern: 6              1            1   1          1   2   1        1   3   3   1      1   4   6   4   1    1   5  10  10   5   1
    Java Program for printing repeated numbers pattern
    import java.util.Scanner;   public class RepeatedPattern { public static void main(String[] args) { Scanner sc = new Scanner(System.in); //Taking rows value from the user System.out.println(“Enter the number of rows for pattern: “);   int rows = sc.nextInt(); for (int i = 1; i <= rows; i++) { for (int j = 1; j <= i; j++) { System.out.print(i+” “); }   System.out.println(); } sc.close(); } }
    Output for the above program
    Enter the number of rows for pattern: 6 2 2  3 3 3  4 4 4 4  5 5 5 5 5  6 6 6 6 6 6
    Java Program to Print Inverted Half Pyramid with numbers
    import java.io.*; import java.util.Scanner;   public class HalfPyramid {   public static void main(String[] args) { Scanner sc = new Scanner(System.in); // Scanner Object System.out.println(“Enter the number of rows for pattern: “); // Taking rows value from the user with scanner int rows = sc.nextInt();   for(int row = rows; row >= 1; –row) { for(int col = 1; col <= row; ++col) { System.out.print(col + ” “); } System.out.println(); } sc.close(); } }
    Output for the above program
    Enter the number of rows for pattern: 6   1 2 3 4 5 6  1 2 3 4 5  1 2 3 4  1 2 3  1 2  1
    Java Program to print repeated number pattern
    import java.io.*; import java.util.Scanner;   public class MainClass { public static void main(String[] args) { Scanner sc = new Scanner(System.in);          // Scanner Object System.out.println(“Enter the number of rows for pattern: “); int rows = sc.nextInt();         // Taking rows value from the user with scanner   for (int row = 1; row <= rows; row++) {   for (int col = 1; col <= row; col++) { System.out.print(col+” “); }   for (int col = row-1; col >= 1; col–) { System.out.print(col+” “); }   System.out.println(); } sc.close(); } }
    Output for the above program
    Enter the number of rows for pattern: 6 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
    After numeric pattern programs, we have character pattern programs in java.

    Character Pattern Programs With Java

    Java program to print right triangle character pattern
    import java.io.*; import java.util.Scanner;   public class RightAlphaTri { public static void main(String[] args) { int alphabet = 65;     //ASCII value of A is 65 Scanner sc = new Scanner(System.in);  // Scanner Object   System.out.println(“Enter the number of rows for pattern: “); // Taking rows value from the user with a scanner   int rows = sc.nextInt(); for (int row = 0; row <= rows; row++) { for (int col = 0; col <= row; col++) { System.out.print((char) (alphabet + col) + ” “); } System.out.println(); } sc.close(); } }
    Output for the above program
    Enter the number of rows for pattern: 6  A B  A B C  A B C D  A B C D E  A B C D E F  A B C D E F G
    Java program to print repeated character pattern
    import java.io.*; import java.util.Scanner;   public class Edureka { public static void main(String[] args) { int alphabet = 65; Scanner sc = new Scanner(System.in);  // Scanner Object System.out.println(“Enter the number of rows for pattern: “);   // Taking rows value from the user with a scanner   int rows = sc.nextInt(); for (int row = 0; row<= rows; row++) { for (int col = 0; col <= row; col++) { System.out.print((char) alphabet + ” “); } alphabet++; System.out.println(); } sc.close(); } }
    Output for the above program
    Enter the number of rows for pattern: 6  B B  C C C  D D D D  E E E E E  F F F F F F
    Java Program to Print Pyramid Pattern with alphabets
    import java.io.*; import java.util.Scanner;   public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in);  // Scanner Object System.out.println(“Enter the number of rows for pattern: “); // Taking rows value from the user with scanner int rows = sc.nextInt(); int alphabet = 65; for (int row = 0; row <= rows; row++) { for (int col = 8; col > row; col–) { System.out.print(” “); } for (int count = 0; count <= row; count++) { System.out.print((char) (alphabet + count) + ” “); } System.out.println(); } sc.close(); } }
    Output for the above program
    Enter the number of rows for pattern:  6         A         A B        A B C       A B C D      A B C D E     A B C D E F    A B C D E F G 

    This was all printing patterns using java. To get in-depth knowledge of core Java and advanced java, J2EE  SOA training along with its various applications and real-time projects using Servlets, Spring with Aspect-Oriented Programming (AOP) architecture, Hibernate Framework, and Struts through JDBC you can enroll in Certified Java Training in Chennai or Certified Java Training in Bangalore by FITA or a virtual class for this course, at an affordable price, bundled with real-time projects, certification, support, and career guidance assistance and an active placement cell, to make you an industry required certified java developer.

    FITA’s courses training is delivered by professional experts who have worked in the software development and testing industry for a minimum of 10+ years, and have experience of working with different software frameworks and software testing designs.






    Quick Enquiry

    Contact Us

    Chennai

      93450 45466

    Bangalore

     93450 45466

    Coimbatore

     95978 88270

    For Hiring

     93840 47472
     hr@fita.in

    Corporate Training

     90036 23340


    FITA Academy Branches

    Chennai
    Bangalore
    Coimbatore
    Others
    FITA Academy - Velachery
    37F Velachery Main Road,
    Velachery, Chennai - 600042
    Tamil Nadu
    Next to Adyar Ananda Bhavan

        :   93450 45466

    FITA Academy - Anna Nagar
    No 14, Block No, 338, 2nd Ave,
    Anna Nagar,
    Chennai 600 040, Tamil Nadu
    Next to Santhosh Super Market

        :   93450 45466

    FITA Academy - T Nagar
    05, 5th Floor, Challa Mall,
    T Nagar,
    Chennai 600 017, Tamil Nadu
    Opposite to Pondy Bazaar Globus

        :   93450 45466

    FITA Academy - Tambaram
    Nehru Nagar, Kadaperi,
    GST Road, West Tambaram,
    Chennai 600 045, Tamil Nadu
    Opposite to Saravana Jewellers Near MEPZ

        :   93450 45466

    FITA Academy - Thoraipakkam
    5/350, Old Mahabalipuram Road,
    Okkiyam Thoraipakkam,
    Chennai 600 097, Tamil Nadu
    Next to Cognizant Thoraipakkam Office and Opposite to Nilgris Supermarket

        :   93450 45466

    FITA Academy Marathahalli
    No 7, J J Complex,
    ITPB Road, Aswath Nagar,
    Marathahalli Post,
    Bengaluru 560037

        :   93450 45466

    FITA Academy - Saravanampatty
    First Floor, Promenade Tower,
    171/2A, Sathy Road, Saravanampatty,
    Coimbatore - 641035
    Tamil Nadu

        :   95978 88270

    FITA Academy - Singanallur
    348/1, Kamaraj Road,
    Varadharajapuram, Singanallur,
    Coimbatore - 641015
    Tamil Nadu

        :   95978 88270

    FITA Academy - Madurai
    No.2A, Sivanandha salai,
    Arapalayam Cross Road,
    Ponnagaram Colony,
    Madurai - 625016, Tamil Nadu

        :   97900 94102

  • Trending Courses

    JAVA Training In Chennai Dot Net Training In Chennai Software Testing Training In Chennai Cloud Computing Training In Chennai AngularJS Training in Chennai Big Data Hadoop Training In Chennai Android Training In Chennai iOS Training In Chennai Web Designing Course In Chennai PHP Training In Chennai Digital Marketing Course In Chennai SEO Training In Chennai

    Oracle Training In Chennai Selenium Training In Chennai Data Science Course In Chennai RPA Training In Chennai DevOps Training In Chennai C / C++ Training In Chennai UNIX Training In Chennai Placement Training In Chennai German Classes In Chennai Python Training in Chennai Artificial Intelligence Course in Chennai AWS Training in Chennai Core Java Training in Chennai Javascript Training in ChennaiHibernate Training in ChennaiHTML5 Training in ChennaiPhotoshop Classes in ChennaiMobile Testing Training in ChennaiQTP Training in ChennaiLoadRunner Training in ChennaiDrupal Training in ChennaiManual Testing Training in ChennaiSpring Training in ChennaiStruts Training in ChennaiWordPress Training in ChennaiSAS Training in ChennaiClinical SAS Training in ChennaiBlue Prism Training in ChennaiMachine Learning course in ChennaiMicrosoft Azure Training in ChennaiUiPath Training in ChennaiMicrosoft Dynamics CRM Training in ChennaiUI UX Design course in ChennaiSalesforce Training in ChennaiVMware Training in ChennaiR Training in ChennaiAutomation Anywhere Training in ChennaiTally course in ChennaiReactJS Training in ChennaiCCNA course in ChennaiEthical Hacking course in ChennaiGST Training in ChennaiIELTS Coaching in ChennaiSpoken English Classes in ChennaiSpanish Classes in ChennaiJapanese Classes in ChennaiTOEFL Coaching in ChennaiFrench Classes in ChennaiInformatica Training in ChennaiInformatica MDM Training in ChennaiBig Data Analytics courses in ChennaiHadoop Admin Training in ChennaiBlockchain Training in ChennaiIonic Training in ChennaiIoT Training in ChennaiXamarin Training In ChennaiNode JS Training In ChennaiContent Writing Course in ChennaiAdvanced Excel Training In ChennaiCorporate Training in ChennaiEmbedded Training In ChennaiLinux Training In ChennaiOracle DBA Training In ChennaiPEGA Training In ChennaiPrimavera Training In ChennaiTableau Training In ChennaiSpark Training In ChennaiGraphic Design Courses in ChennaiAppium Training In ChennaiSoft Skills Training In ChennaiJMeter Training In ChennaiPower BI Training In ChennaiSocial Media Marketing Courses In ChennaiTalend Training in ChennaiHR Courses in ChennaiGoogle Cloud Training in ChennaiSQL Training In ChennaiCCNP Training in Chennai

  • Are You Located in Any of these Areas

    Adyar, Adambakkam, Anna Salai, Ambattur, Ashok Nagar, Aminjikarai, Anna Nagar, Besant Nagar, Chromepet, Choolaimedu, Guindy, Egmore, K.K. Nagar, Kodambakkam, Koyambedu, Ekkattuthangal, Kilpauk, Meenambakkam, Medavakkam, Nandanam, Nungambakkam, Madipakkam, Teynampet, Nanganallur, Navalur, Mylapore, Pallavaram, Purasaiwakkam, OMR, Porur, Pallikaranai, Poonamallee, Perambur, Saidapet, Siruseri, St.Thomas Mount, Perungudi, T.Nagar, Sholinganallur, Triplicane, Thoraipakkam, Tambaram, Vadapalani, Valasaravakkam, Villivakkam, Thiruvanmiyur, West Mambalam, Velachery and Virugambakkam.

    FITA Velachery or T Nagar or Thoraipakkam OMR or Anna Nagar or Tambaram branch is just few kilometre away from your location. If you need the best training in Chennai, driving a couple of extra kilometres is worth it!