• Java
    • JAXB Tutorial
      • What is JAXB
      • JAXB Marshalling Example
      • JAXB UnMarshalling Example
  • Spring Tutorial
    • Spring Core Tutorial
    • Spring MVC Tutorial
      • Quick Start
        • Flow Diagram
        • Hello World Example
        • Form Handling Example
      • Handler Mapping
        • BeanNameUrlHandlerMapping
        • ControllerClassNameHandlerMapping
        • SimpleUrlHandlerMapping
      • Validation & Exception Handling
        • Validation+Annotations
        • Validation+ResourceBundle
        • @ExceptionHandler
        • @ControllerAdvice
        • Custom Exception Handling
      • Form Tag Library
        • Textbox Example
        • TextArea Example
        • Password Example
        • Dropdown Box Example
        • Checkboxes Example
        • Radiobuttons Example
        • HiddenValue Example
      • Misc
        • Change Config file name
    • Spring Boot Tutorial
  • Hibernate Tutorial
  • REST Tutorial
    • JAX-RS REST @PathParam Example
    • JAX-RS REST @QueryParam Example
    • JAX-RS REST @DefaultValue Example
    • JAX-RS REST @Context Example
    • JAX-RS REST @MatrixParam Example
    • JAX-RS REST @FormParam Example
    • JAX-RS REST @Produces Example
    • JAX-RS REST @Consumes Example
    • JAX-RS REST @Produces both XML and JSON Example
    • JAX-RS REST @Consumes both XML and JSON Example
  • Miscellaneous
    • JSON Parser
      • Read a JSON file
      • Write JSON object to File
      • Read / Write JSON using GSON
      • Java Object to JSON using JAXB
    • CSV Parser
      • Read / Write CSV file
      • Read/Parse/Write CSV File – OpenCSV
      • Export data into a CSV File
      • CsvToBean and BeanToCsv – OpenCSV

JavaInterviewPoint

Java Development Tutorials

58 Number Pattern Programs In Java | Pyramid and Diamond Pattern Programs

June 17, 2018 by javainterviewpoint 168 Comments

In this article, we will learn to print the different Number pattern programs in Java. This is one of the important Java interview questions for fresher. Let’s look into the below possible number pattern programs

Number Pattern Programs in Java

Number Pattern Programs in Java 5

Number Pattern Programs in Java 8

Number Pattern Programs in Java 10

Number Pattern Programs In Java

Pattern 1:

package com.javainterviewpoint;

import java.util.Scanner;

public class Pattern1
{
    public static void main(String[] args)
    {
        // Create a new Scanner object
        Scanner scanner = new Scanner(System.in);

        // Get the number of rows from the user
        System.out.println("Enter the number of rows to print the pattern ");

        int rows = scanner.nextInt();
        System.out.println("** Printing the pattern... **");
        for (int i = 1; i <= rows; i++)
        {
            for (int j = 1; j <= i; j++)
            {
                System.out.print(j + " ");
            }
            System.out.println();
        }
    }
}

Output

Enter the number of rows to print the pattern 
5
** Printing the pattern... **
1 
1 2 
1 2 3 
1 2 3 4 
1 2 3 4 5 

Pattern 2:

package com.javainterviewpoint;

import java.util.Scanner;

public class Pattern2
{
    public static void main(String[] args)
    {
        // Create a new Scanner object
        Scanner scanner = new Scanner(System.in);

        // Get the number of rows from the user
        System.out.println("Enter the number of rows to print the pattern ");

        int rows = scanner.nextInt();
        
        System.out.println("** Printing the pattern... **");
        
        for (int i = 1; i <= rows; i++)
        {
            for (int j = 1; j <= i; j++)
            {
                System.out.print(i + " ");
            }
            System.out.println();
        }
    }
}

Output

Enter the number of rows to print the pattern 
5
** Printing the pattern... **
1 
2 2 
3 3 3 
4 4 4 4 
5 5 5 5 5

Pattern 3:

package com.javainterviewpoint;

import java.util.Scanner;

public class Pattern3
{
    public static void main(String[] args)
    {
        // Create a new Scanner object
        Scanner scanner = new Scanner(System.in);

        // Get the number of rows from the user
        System.out.println("Enter the number of rows to print the pattern ");

        int rows = scanner.nextInt();

        System.out.println("** Printing the pattern... **");

        for (int i = 1; i <= rows; i++)
        {
            for (int j = 1; j <= i; j++)
            {
                System.out.print(j + " ");
            }
            System.out.println();
        }
        for (int i = rows; i >= 1; i--)
        {
            for (int j = 1; j < i; j++)
            {
                System.out.print(j + " ");
            }
            System.out.println();
        }
    }
}

Output

Enter the number of rows to print the pattern 
5
** Printing the pattern... **
1 
1 2 
1 2 3 
1 2 3 4 
1 2 3 4 5 
1 2 3 4 
1 2 3 
1 2 
1

Pattern 4:

package com.javainterviewpoint;

import java.util.Scanner;

public class Pattern4
{
    public static void main(String[] args)
    {
        // Create a new Scanner object
        Scanner scanner = new Scanner(System.in);

        // Get the number of rows from the user
        System.out.println("Enter the number of rows to print the pattern ");

        int rows = scanner.nextInt();
        
        System.out.println("** Printing the pattern... **");
        
        for (int i = rows; i >= 1; i--)
        {
            for (int j = 1; j <= i; j++)
            {
                System.out.print(j + " ");
            }
            System.out.println();
        }

        for (int i = 1; i <= rows; i++)
        {
            for (int j = 1; j <= i; j++)
            {
                System.out.print(j + " ");
            }
            System.out.println();
        }
    }
}

Output

Enter the number of rows to print the pattern 
5
** Printing the pattern... **
1 2 3 4 5 
1 2 3 4 
1 2 3 
1 2 
1 
1 
1 2 
1 2 3 
1 2 3 4 
1 2 3 4 5

Pattern 5:

package com.javainterviewpoint;

import java.util.Scanner;

public class Pattern5
{
    public static void main(String[] args)
    {
        // Create a new Scanner object
        Scanner scanner = new Scanner(System.in);

        // Get the number of rows from the user
        System.out.println("Enter the number of rows to print the pattern ");

        int rows = scanner.nextInt();

        System.out.println("** Printing the pattern... **");

        for (int i = rows; i >= 1; i--)
        {
            for (int j = i; j >= 1; j--)
            {
                System.out.print(j + " ");
            }
            System.out.println();
        }

        for (int i = 1; i <= rows; i++)
        {
            for (int j = i; j >= 1; j--)
            {
                System.out.print(j + " ");
            }
            System.out.println();
        }
    }
}

Output

Enter the number of rows to print the pattern 
5
** Printing the pattern... **
5 4 3 2 1 
4 3 2 1 
3 2 1 
2 1 
1 
1 
2 1 
3 2 1 
4 3 2 1 
5 4 3 2 1

Pattern 6:

package com.javainterviewpoint;

import java.util.Scanner;

public class Pattern6
{
    public static void main(String[] args)
    {
        // Create a new Scanner object
        Scanner scanner = new Scanner(System.in);

        // Get the number of rows from the user
        System.out.println("Enter the number of rows to print the pattern ");

        int rows = scanner.nextInt();

        System.out.println("** Printing the pattern... **");

        for (int i = 1; i <= rows; i++)
        {
            for (int j = rows; j > i; j--)
            {
                System.out.print(" ");
            }
            for (int k = 1; k <= i; k++)
            {
                System.out.print(k + " ");
            }
            System.out.println();
        }
    }
}

Output

Enter the number of rows to print the pattern 
5
** Printing the pattern... **
    1 
   1 2 
  1 2 3 
 1 2 3 4 
1 2 3 4 5 

Pattern 7:

package com.javainterviewpoint;

import java.util.Scanner;

public class Pattern7
{
    public static void main(String[] args)
    {
        // Create a new Scanner object
        Scanner scanner = new Scanner(System.in);

        // Get the number of rows from the user
        System.out.println("Enter the number of rows to print the pattern ");

        int rows = scanner.nextInt();

        System.out.println("** Printing the pattern... **");

        for (int i = 1; i <= rows; i++)
        {
            for (int j = rows; j >= i; j--)
            {
                System.out.print(j + " ");
            }
            System.out.println();
        }
    }
}

Output

Enter the number of rows to print the pattern 
5
** Printing the pattern... **
5 4 3 2 1 
5 4 3 2 
5 4 3 
5 4 
5

Pattern 8:

package com.javainterviewpoint;

import java.util.Scanner;

public class Pattern8
{
    public static void main(String[] args)
    {
        // Create a new Scanner object
        Scanner scanner = new Scanner(System.in);

        // Get the number of rows from the user
        System.out.println("Enter the number of rows to print the pattern ");

        int rows = scanner.nextInt();
        
        System.out.println("** Printing the pattern... **");
        
        for (int i = rows; i >= 1; i--)
        {
            for (int j = rows; j >= i; j--)
            {
                System.out.print(j + " ");
            }
            System.out.println();
        }
    }
}

Output

Enter the number of rows to print the pattern 
5
** Printing the pattern... **
5 
5 4 
5 4 3 
5 4 3 2 
5 4 3 2 1

Pattern 9:

package com.javainterviewpoint;

import java.util.Scanner;

public class Pattern9
{
    public static void main(String[] args)
    {
        // Create a new Scanner object
        Scanner scanner = new Scanner(System.in);

        // Get the number of rows from the user
        System.out.println("Enter the number of rows to print the pattern ");

        int rows = scanner.nextInt();
        
        System.out.println("** Printing the pattern... **");
        
        for (int i = rows; i >= 1; i--)
        {
            for (int j = 1; j <= i; j++)
            {
                System.out.print(j + " ");
            }
            System.out.println();
        }
    }
}

Output

Enter the number of rows to print the pattern 
5
** Printing the pattern... **
1 2 3 4 5 
1 2 3 4 
1 2 3 
1 2 
1

Pattern 10:

package com.javainterviewpoint;

import java.util.Scanner;

public class Pattern10
{
    public static void main(String[] args)
    {
        // Create a new Scanner object
        Scanner scanner = new Scanner(System.in);

        // Get the number of rows from the user
        System.out.println("Enter the number of rows to print the pattern ");

        int rows = scanner.nextInt();
        int k = 1;
        
        System.out.println("** Printing the pattern... **");
        
        for (int i = 1; i <= rows; i++)
        {
            for (int j = 1; j <= i; j++)
            {
                System.out.print(k + " ");
                k++;
            }
            System.out.println();
        }
    }
}

Output

Enter the number of rows to print the pattern 
5
** Printing the pattern... **
1 
2 3 
4 5 6 
7 8 9 10 
11 12 13 14 15

Pattern 11:

package com.javainterviewpoint;

import java.util.Scanner;

public class Pattern11
{
    public static void main(String[] args)
    {
        // Create a new Scanner object
        Scanner scanner = new Scanner(System.in);

        // Get the number of rows from the user
        System.out.println("Enter the number of rows to print the pattern ");

        int rows = scanner.nextInt();

        System.out.println("** Printing the pattern... **");

        for (int i = 1; i <= rows; i++)
        {
            for (int j = i; j >= 1; j--)
            {
                System.out.print(j + " ");
            }
            System.out.println();
        }
    }
}

Output

Enter the number of rows to print the pattern 
5
** Printing the pattern... **
1 
2 1 
3 2 1 
4 3 2 1 
5 4 3 2 1

Pattern 12:

package com.javainterviewpoint;

import java.util.Scanner;

public class Pattern12
{
    public static void main(String[] args)
    {
        // Create a new Scanner object
        Scanner scanner = new Scanner(System.in);

        // Get the number of rows from the user
        System.out.println("Enter the number of rows to print the pattern ");

        int rows = scanner.nextInt();

        System.out.println("** Printing the pattern... **");

        for (int i = 1; i <= rows; i++)
        {
            int temp = i;
            for (int j = i; j >= 1; j--)
            {
                System.out.print(temp + " ");
                temp = temp + rows;
            }
            System.out.println();
        }
    }
}

Output

Enter the number of rows to print the pattern 
5
** Printing the pattern... **
1 
2 7 
3 8 13 
4 9 14 19 
5 10 15 20 25

Pattern 13:

package com.javainterviewpoint;

import java.util.Scanner;

public class Pattern13
{
    public static void main(String[] args)
    {
        // Create a new Scanner object
        Scanner scanner = new Scanner(System.in);

        // Get the number of rows from the user
        System.out.println("Enter the number of rows to print the pattern ");

        int rows = scanner.nextInt();

        System.out.println("** Printing the pattern... **");

        for (int i = 1; i <= rows; i++)
        {
            for (int j = rows; j > i; j--)
            {
                System.out.print(" ");
            }

            int temp = 1;
            for (int k = 1; k <= i; k++)
            {
                System.out.print(temp + " ");
                temp = temp * (i - k) / (k);
            }
            System.out.println();
        }
    }
}

Output

Enter the number of rows to print the pattern 
5
** Printing the pattern... **
    1 
   1 1 
  1 2 1 
 1 3 3 1 
1 4 6 4 1

Pattern 14:

package com.javainterviewpoint;

import java.util.Scanner;

public class Pattern14
{
    public static void main(String[] args)
    {
        // Create a new Scanner object
        Scanner scanner = new Scanner(System.in);

        // Get the number of rows from the user
        System.out.println("Enter the number of rows to print the pattern ");

        int rows = scanner.nextInt();

        System.out.println("** Printing the pattern... **");

        for (int i = 1; i <= rows; i++)
        {
            for (int j = 1; j <= i; j++)
            {
                System.out.print(j + " ");
            }
            for (int k = i - 1; k >= 1; k--)
            {
                System.out.print(k + " ");
            }
            System.out.println();
        }
    }
}

Output

Enter the number of rows to print the pattern 
5
** Printing the 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

Pattern 15:

package com.javainterviewpoint;

import java.util.Scanner;

public class Pattern15
{
    public static void main(String[] args)
    {
        // Create a new Scanner object
        Scanner scanner = new Scanner(System.in);

        // Get the number of rows from the user
        System.out.println("Enter the number of rows to print the pattern ");

        int rows = scanner.nextInt();
        
        System.out.println("** Printing the pattern... **");
        
        for (int i = 1; i <= rows; i++)
        {
            for (int j = 1; j < i; j++)
            {
                System.out.print(" ");
            }
            for (int k = 1; k <= rows - i + 1; k++)
            {
                System.out.print(k + " ");
            }
            System.out.println();
        }
    }
}

Output

Enter the number of rows to print the pattern 
5
** Printing the pattern... **
1 2 3 4 5 
 1 2 3 4 
  1 2 3 
   1 2 
    1 

Pattern 16:

package com.javainterviewpoint;

import java.util.Scanner;

public class Pattern16
{
    public static void main(String[] args)
    {
        // Create a new Scanner object
        Scanner scanner = new Scanner(System.in);

        // Get the number of rows from the user
        System.out.println("Enter the number of rows to print the pattern ");

        int rows = scanner.nextInt();

        System.out.println("** Printing the pattern... **");

        for (int i = 1; i <= rows; i++)
        {
            for (int j = rows; j > i; j--)
            {
                System.out.print(" ");
            }

            for (int k = 1; k <= i; k++)
            {
                System.out.print(k + " ");
            }
            System.out.println();
        }
        for (int i = 1; i <= rows; i++)
        {
            for (int j = 1; j <= i; j++)
            {
                System.out.print(" ");
            }
            for (int k = 1; k <= rows - i; k++)
            {
                System.out.print(k + " ");
            }
            System.out.println();
        }
    }
}

Output

Enter the number of rows to print the pattern 
5
** Printing the pattern... **
    1 
   1 2 
  1 2 3 
 1 2 3 4 
1 2 3 4 5 
 1 2 3 4 
  1 2 3 
   1 2 
    1

Pattern 17:

package com.javainterviewpoint;

import java.util.Scanner;

public class Pattern17
{
    public static void main(String[] args)
    {
        // Create a new Scanner object
        Scanner scanner = new Scanner(System.in);

        // Get the number of rows from the user
        System.out.println("Enter the number of rows to print the pattern ");

        int rows = scanner.nextInt();

        System.out.println("** Printing the pattern... **");

        for (int i = 1; i <= rows; i++)
        {
            for (int j = 1; j < i; j++)
            {
                System.out.print(" ");
            }

            for (int k = i; k <= rows; k++)
            {
                System.out.print(k);
            }
            System.out.println();
        }
        for (int i = rows; i >= 1; i--)
        {
            for (int j = 1; j < i; j++)
            {
                System.out.print(" ");
            }

            for (int k = i; k <= rows; k++)
            {
                System.out.print(k);
            }
            System.out.println();
        }
    }
}

Output

Enter the number of rows to print the pattern 
5
** Printing the pattern... **
12345
 2345
  345
   45
    5
    5
   45
  345
 2345
12345

Pattern 18:

package com.javainterviewpoint;

import java.util.Scanner;

public class Pattern18
{
    public static void main(String[] args)
    {
        // Create a new Scanner object
        Scanner scanner = new Scanner(System.in);

        // Get the number of rows from the user
        System.out.println("Enter the number of rows to print the pattern ");

        int rows = scanner.nextInt();

        System.out.println("** Printing the pattern... **");

        for (int i = 1; i <= rows; i++)
        {
            for (int j = 1; j < i; j++)
            {
                System.out.print(" ");
            }

            for (int k = i; k <= rows; k++)
            {
                System.out.print(k + " ");
            }
            System.out.println();
        }
        for (int i = rows; i >= 1; i--)
        {
            for (int j = 1; j < i; j++)
            {
                System.out.print(" ");
            }

            for (int k = i; k <= rows; k++)
            {
                System.out.print(k + " ");
            }
            System.out.println();
        }

    }
}

Output

Enter the number of rows to print the pattern 
5
** Printing the pattern... **
1 2 3 4 5 
 2 3 4 5 
  3 4 5 
   4 5 
    5 
    5 
   4 5 
  3 4 5 
 2 3 4 5 
1 2 3 4 5 

Pattern 19:

package com.javainterviewpoint;

import java.util.Scanner;

public class Pattern19
{
    public static void main(String[] args)
    {
        // Create a new Scanner object
        Scanner scanner = new Scanner(System.in);

        // Get the number of rows from the user
        System.out.println("Enter the number of rows to print the pattern ");

        int rows = scanner.nextInt();
        
        System.out.println("** Printing the pattern... **");
        
        for (int i = rows; i >= 1; i--)
        {
            for (int j = 1; j < i; j++)
            {
                System.out.print(" ");
            }

            for (int k = i; k <= rows; k++)
            {
                System.out.print(k + " ");
            }
            System.out.println();
        }

    }
}

Output

Enter the number of rows to print the pattern 
5
** Printing the pattern... **
    5 
   4 5 
  3 4 5 
 2 3 4 5 
1 2 3 4 5

Pattern 20:

package com.javainterviewpoint;

import java.util.Scanner;

public class Pattern20
{
    public static void main(String[] args)
    {
        // Create a new Scanner object
        Scanner scanner = new Scanner(System.in);

        // Get the number of rows from the user
        System.out.println("Enter the number of rows to print the pattern ");

        int rows = scanner.nextInt();

        System.out.println("** Printing the pattern... **");

        for (int i = 1; i <= rows; i++)
        {
            for (int j = rows; j > i; j--)
            {
                System.out.print(" ");
            }
            for (int k = 1; k <= i; k++)
            {
                System.out.print(k);
            }
            for (int l = i - 1; l >= 1; l--)
            {
                System.out.print(l);
            }
            System.out.println();
        }
    }
}

Output

Enter the number of rows to print the pattern 
5
** Printing the pattern... **
    1
   121
  12321
 1234321
123454321

Pattern 21:

package com.javainterviewpoint;

import java.util.Scanner;

public class Pattern21
{
    public static void main(String[] args)
    {
        // Create a new Scanner object
        Scanner scanner = new Scanner(System.in);

        // Get the number of rows from the user
        System.out.println("Enter the number of rows to print the pattern ");

        int rows = scanner.nextInt();
        
        System.out.println("** Printing the pattern... **");
        
        for (int i = 1; i <= rows; i++)
        {
            for (int j = 1; j <= i; j++)
            {
                System.out.print(j % 2 + " ");
            }

            System.out.println();
        }
    }
}

Output

Enter the number of rows to print the pattern 
5
** Printing the pattern... **
1 
1 0 
1 0 1 
1 0 1 0 
1 0 1 0 1

Pattern 22:

package com.javainterviewpoint;

import java.util.Scanner;

public class Pattern22
{
    public static void main(String[] args)
    {
        // Create a new Scanner object
        Scanner scanner = new Scanner(System.in);

        // Get the number of rows from the user
        System.out.println("Enter the number of rows to print the pattern ");

        int rows = scanner.nextInt();
        
        System.out.println("** Printing the pattern... **");
        
        for (int i = 1; i <= rows; i++)
        {
            for (int j = 1; j < i; j++)
            {
                System.out.print("0 ");
            }
            System.out.print(i + " ");
            for (int k = i; k < rows; k++)
            {
                System.out.print("0 ");
            }
            System.out.println();
        }
    }
}

Output

Enter the number of rows to print the pattern 
5
** Printing the pattern... **
1 0 0 0 0 
0 2 0 0 0 
0 0 3 0 0 
0 0 0 4 0 
0 0 0 0 5 

Pattern 23:

package com.javainterviewpoint;

import java.util.Scanner;

public class Pattern23
{
    public static void main(String[] args)
    {
        // Create a new Scanner object
        Scanner scanner = new Scanner(System.in);

        // Get the number of rows from the user
        System.out.println("Enter the number of rows to print the pattern ");

        int rows = scanner.nextInt();

        System.out.println("** Printing the pattern... **");

        for (int i = 1; i <= rows; i++)
        {
            for (int j = rows; j > i; j--)
            {
                System.out.print(1 + " ");
            }

            for (int k = 1; k <= i; k++)
            {
                System.out.print(i + " ");
            }
            System.out.println();
        }
    }
}

Output

Enter the number of rows to print the pattern 
5
** Printing the pattern... **
1 1 1 1 1 
1 1 1 2 2 
1 1 3 3 3 
1 4 4 4 4 
5 5 5 5 5

Pattern 24:

package com.javainterviewpoint;

import java.util.Scanner;

public class Pattern24
{
    public static void main(String[] args)
    {
        // Create a new Scanner object
        Scanner scanner = new Scanner(System.in);

        // Get the number of rows from the user
        System.out.println("Enter the number of rows to print the pattern ");

        int rows = scanner.nextInt();

        System.out.println("** Printing the pattern... **");

        for (int i = 1; i <= rows; i++)
        {
            for (int j = i; j <= rows; j++)
            {
                System.out.print(j + " ");
            }
            for (int k = rows - 1; k >= i; k--)
            {
                System.out.print(k + " ");
            }
            System.out.println();
        }
    }
}

Output

Enter the number of rows to print the pattern 
5
** Printing the pattern... **
1 2 3 4 5 4 3 2 1 
2 3 4 5 4 3 2 
3 4 5 4 3 
4 5 4 
5

Pattern 25:

package com.javainterviewpoint;

import java.util.Scanner;

public class Pattern25
{
    public static void main(String[] args)
    {
        // Create a new Scanner object
        Scanner scanner = new Scanner(System.in);

        // Get the number of rows from the user
        System.out.println("Enter the number of rows to print the pattern ");

        int rows = scanner.nextInt();

        System.out.println("** Printing the pattern... **");

        for (int i = 1; i <= rows; i++)
        {
            for (int j = rows; j > i; j--)
            {
                System.out.print(" ");
            }

            for (int k = 1; k <= i; k++)
            {
                System.out.print(i + " ");
            }
            System.out.println();
        }
    }
}

Output

Enter the number of rows to print the pattern 
5
** Printing the pattern... **
    1 
   2 2 
  3 3 3 
 4 4 4 4 
5 5 5 5 5 

Pattern 26:

package com.javainterviewpoint;

import java.util.Scanner;

public class Pattern26
{
    public static void main(String[] args)
    {
        // Create a new Scanner object
        Scanner scanner = new Scanner(System.in);

        // Get the number of rows from the user
        System.out.println("Enter the number of rows to print the pattern ");

        int rows = scanner.nextInt();
        
        System.out.println("** Printing the pattern... **");
        
        for (int i = rows; i >= 1; i--)
        {
            for (int j = i; j < rows; j++)
            {
                System.out.print(j + " ");
            }

            for (int k = rows - i; k < rows; k++)
            {
                System.out.print(5 + " ");
            }
            System.out.println();
        }
    }
}

Output

Enter the number of rows to print the pattern 
5
** Printing the pattern... **
5 5 5 5 5 
4 5 5 5 5 
3 4 5 5 5 
2 3 4 5 5 
1 2 3 4 5 

Pattern 27:

package com.javainterviewpoint;

import java.util.Scanner;

public class Pattern27
{
    public static void main(String[] args)
    {
        // Create a new Scanner object
        Scanner scanner = new Scanner(System.in);

        // Get the number of rows from the user
        System.out.println("Enter the number of rows to print the pattern ");

        int rows = scanner.nextInt();
        int k = 1;
        
        System.out.println("** Printing the pattern... **");
        
        for (int i = 1; i <= rows; i++)
        {
            k=i;
            for (int j = 1; j <= i; j++)
            {
                System.out.print(k + " ");
                k = k + rows - j; 
            }
            System.out.println();
        }
    }
}

Output

Enter the number of rows to print the pattern 
5
** Printing the pattern... **
1 
2 6 
3 7 10 
4 8 11 13 
5 9 12 14 15 

Pattern 28:

package com.javainterviewpoint;

import java.util.Scanner;

public class Pattern28
{
    public static void main(String[] args)
    {
        // Create a new Scanner object
        Scanner scanner = new Scanner(System.in);

        // Get the number of rows from the user
        System.out.println("Enter the number of rows to print the pattern ");

        int rows = scanner.nextInt();
        System.out.println("** Printing the pattern... **");
        int temp = 1;
        for(int i=1; i<=rows/2+1; i++)
        {
            for(int j=1;j<=i;j++)
            {
                System.out.print(temp*j+" ");
            }
            System.out.println();
            temp++;
        }
        for(int i=1; i<=rows/2; i++)
        {
            for(int j=1;j<=rows/2+1-i;j++)
            {
                System.out.print(temp*j+" ");
            }
            System.out.println();
            temp++;
        }
    }
}

Output

Enter the number of rows to print the pattern 
7
** Printing the pattern... **
1 
2 4 
3 6 9 
4 8 12 16 
5 10 15 
6 12 
7

Pattern 29:

package com.javainterviewpoint;

import java.util.Scanner;

public class Pattern29
{
    public static void main(String[] args)
    {
        // Create a new Scanner object
        Scanner scanner = new Scanner(System.in);

        // Get the number of rows from the user
        System.out.println("Enter the number of rows to print the pattern ");

        int rows = scanner.nextInt();
        System.out.println("** Printing the pattern... **");

        for (int i = 0; i < rows; i++)
        {
            for (int j = 0; j <= i; j++)
            {
                if (j % 2 == 0)
                {
                    System.out.print(1 + j * rows - (j - 1) * j / 2 + i - j + " ");
                } else
                {
                    System.out.print(1 + j * rows - (j - 1) * j / 2 + rows - 1 - i + " ");
                }
            }

         System.out.println();
        }
    }
}

Output

Enter the number of rows to print the pattern 
5
** Printing the pattern... **
1 
2 9 
3 8 10 
4 7 11 14 
5 6 12 13 15

Pattern 30:

package com.javainterviewpoint;

import java.util.Scanner;

public class Pattern30
{
    public static void main(String[] args)
    {
        // Create a new Scanner object
        Scanner scanner = new Scanner(System.in);

        // Get the number of rows from the user
        System.out.println("Enter the number of rows to print the pattern ");

        int rows = scanner.nextInt();
        System.out.println("** Printing the pattern... **");
        for (int i = 0; i < rows; i++)
        {
            for (int j = 0; j < rows; j++)
            {
                if (j % 2 == 0)
                    System.out.print((rows * (j)) + i + 1 + " ");
                else
                    System.out.print((rows * (j + 1)) - i + " ");
            }
            System.out.print("\n");
        }
    }
}

Output

Enter the number of rows to print the pattern 
5
** Printing the pattern... **
1 10 11 20 21 
2 9  12 19 22 
3 8  13 18 23 
4 7  14 17 24 
5 6  15 16 25

Pattern 31:

package com.javainterviewpoint;

import java.util.Scanner;

public class Pattern31
{
    public static void main(String[] args)
    {
        // Create a new Scanner object
        Scanner scanner = new Scanner(System.in);

        // Get the number of rows from the user
        System.out.println("Enter the number of rows to print the pattern ");

        int rows = scanner.nextInt();
        int temp = 0;
        System.out.println("** Printing the pattern... **");
        for (int i = rows; i >= 1; i--)
        {
            for (int j = rows ; j >= i; j--)
            {
                System.out.print(j + " ");
                temp =j;
            }
            for (int k = rows - i+1; k < rows; k++)
            {
                System.out.print(temp + " ");
            }
            System.out.println();
        }
    }
}

Output

Enter the number of rows to print the pattern 
5
** Printing the pattern... **
5 5 5 5 5 
5 4 4 4 4 
5 4 3 3 3 
5 4 3 2 2 
5 4 3 2 1

Pattern 32: [ Fibonacci Triangle Pattern ]

package com.javainterviewpoint;

import java.util.Scanner;

public class Pattern32
{
    public static void main(String[] args)
    {
        // Create a new Scanner object
        Scanner scanner = new Scanner(System.in);

        // Get the number of rows from the user
        System.out.println("Enter the number of rows to print the pattern ");

        int rows = scanner.nextInt();

        System.out.println("** Printing the pattern... **");
        for (int i = 1; i <= rows; i++)
        {
            int a = 0;
            int b = 1;

            for (int j = 1; j <= i; j++)
            {
                int c = a + b;
                System.out.print(c + " ");
                a = b;
                b = c;
            }
            System.out.println();
        }
    }
}

Output

Enter the number of rows to print the pattern 
5
** Printing the pattern... **
1 
1 2 
1 2 3 
1 2 3 5 
1 2 3 5 8

Pattern 33:

package com.javainterviewpoint;

import java.util.Scanner;

public class Pattern33
{
    public static void main(String[] args)
    {
        // Create a new Scanner object
        Scanner scanner = new Scanner(System.in);

        // Get the number of rows from the user
        System.out.println("Enter the number of rows to print the pattern ");

        int rows = scanner.nextInt();
        
        System.out.println("** Printing the pattern... **");

        for (int i = rows; i >= 1; i--)
        {
            for (int j = i; j <= rows; j++)
            {
                System.out.print(j + " ");
            }
            for (int k = rows-1; k >= i; k--)
            {
                System.out.print(k + " ");
            }
            System.out.println();
        }

        for (int i = 2; i <= rows; i++)
        {
            for (int j = i; j <= rows; j++)
            {
                System.out.print(j + " ");
            }
            for (int k = rows-1; k >= i; k--)
            {
                System.out.print(k + " ");
            }
            System.out.println();
        }
    }
}

Output

Enter the number of rows to print the pattern 
5
** Printing the pattern... **
5 
4 5 4 
3 4 5 4 3 
2 3 4 5 4 3 2 
1 2 3 4 5 4 3 2 1 
2 3 4 5 4 3 2 
3 4 5 4 3 
4 5 4 
5

Pattern 34:

package com.javainterviewpoint;

import java.util.Scanner;

public class Pattern34
{
    public static void main(String[] args)
    {
        // Create a new Scanner object
        Scanner scanner = new Scanner(System.in);

        // Get the number of rows from the user
        System.out.println("Enter the number of rows to print the pattern ");

        int rows = scanner.nextInt();
        
        System.out.println("** Printing the pattern... **");
        
        for (int i = 1; i <= rows; i++)
        {
            int j = i;
            
            for (int k = 1; k <= rows; k++) 
            { 
                System.out.print(j + " "); 
                j++; 
                if (j > rows)
                    j = 1;
            }
            System.out.println();
        }
        scanner.close();
    }
}

Output

Enter the number of rows to print the pattern 
5
** Printing the pattern... **
1 2 3 4 5 
2 3 4 5 1 
3 4 5 1 2 
4 5 1 2 3 
5 1 2 3 4

Pattern 35:

package com.javainterviewpoint;

import java.util.Scanner;

public class Pattern35
{
    public static void main(String[] args)
    {
        // Create a new Scanner object
        Scanner scanner = new Scanner(System.in);

        // Get the number of rows from the user
        System.out.println("Enter the number of rows to print the pattern ");

        int rows = scanner.nextInt();

        System.out.println("** Printing the pattern... **");
        
        for (int i = 1; i <= rows; i++)
        {
            for (int j = i; j <= rows; j++)
            { 
                 System.out.print(j + " "); 
            } 
            for(int k = i-1; k >= 1; k--)
            {
                System.out.print(k + " ");
            }
            System.out.println();
        }
        scanner.close();
    }
}

Output

Enter the number of rows to print the pattern 
5
** Printing the pattern... **
1 2 3 4 5 
2 3 4 5 1 
3 4 5 2 1 
4 5 3 2 1 
5 4 3 2 1

Pattern 36:

package com.javainterviewpoint;

import java.util.Scanner;

public class Pattern36
{
    public static void main(String[] args)
    {
        // Create a new Scanner object
        Scanner scanner = new Scanner(System.in);

        // Get the number of rows from the user
        System.out.println("Enter the number of rows to print the pattern ");

        int rows = scanner.nextInt();

        System.out.println("** Printing the pattern... **");
        
        for (int i = 1; i <= rows; i++)
        {
            int j = (i * 2) - 1;

            for (int k = 1; k <= rows; k++) 
            { 
                System.out.print(j + " "); 
                j += 2; 
                if (j > (rows * 2) - 1)
                    j = 1;
            }
            System.out.println();
        }
        scanner.close();
    }
}

Output

Enter the number of rows to print the pattern 
5
** Printing the pattern... **
1 3 5 7 9 
3 5 7 9 1 
5 7 9 1 3 
7 9 1 3 5 
9 1 3 5 7

Pattern 37:

package com.javainterviewpoint;

import java.util.Scanner;

public class Pattern37
{
    public static void main(String[] args)
    {
        // Create a new Scanner object
        Scanner scanner = new Scanner(System.in);

        // Get the number of rows from the user
        System.out.println("Enter the number of rows to print the pattern ");

        int rows = scanner.nextInt();
        
        System.out.println("** Printing the pattern... **");
        
        for (int i = 1; i <= rows; i++)
        {
            int j = (i * 2) - 1;

            for (int k = i; k <= rows; k++) 
            { 
                System.out.print(j + " "); 
                j += 2; 
            } 
            for (int l = (i * 2) - 3; l >= 1; l-=2)
            {
                System.out.print(l + " ");
            }
            System.out.println();
        }
        scanner.close();
    }
}

Output

Enter the number of rows to print the pattern 
5
** Printing the pattern... **
1 3 5 7 9 
3 5 7 9 1 
5 7 9 3 1 
7 9 5 3 1 
9 7 5 3 1

Pattern 38:

package com.javainterviewpoint;

import java.util.Scanner;

public class Pattern38
{
    public static void main(String[] args)
    {
        // Create a new Scanner object
        Scanner scanner = new Scanner(System.in);

        // Get the number of rows from the user
        System.out.println("Enter the number of rows to print the pattern ");

        int rows = scanner.nextInt();
        
        System.out.println("** Printing the pattern... **");
        
        for (int i = 1; i <= rows; i++)
        {
            for (int j = 1; j <= i; j++)
            {
                System.out.print(j);
            }
            
            for (int j= i*2 ; j < rows*2; j++) 
            { 
                System.out.print(" "); 
            } 
            for (int l = i; l >= 1; l--)
            {
                System.out.print(l);
            }
            System.out.println();
        }
        scanner.close();
    }
}

Output

Enter the number of rows to print the pattern 
5
** Printing the pattern... **
1        1
12      21
123    321
1234  4321
1234554321

Pattern 39:

package com.javainterviewpoint;

import java.util.Scanner;

public class Pattern39
{
    public static void main(String[] args) 
    { 
        int currentRow = 1;
        int counter = 1;
        
        // Create a new Scanner object
        Scanner scanner = new Scanner(System.in);
        
        // Get the number of rows from the user
        System.out.println("Enter the number of rows to print the pattern ");

        int rows = scanner.nextInt();
        
        System.out.println("** Printing the pattern... **");
        for (int i=1; i<= rows; i++)
        {
            if (i % 2 == 0) 
            {
                int reverse = currentRow + counter - 1;
                for (int j = 0; j<i; j++)
                {
                    System.out.print(reverse--  +" ");
                    counter++;
                }
            }
            else
            {
                for (int j = 1; j<=i; j++)
                {
                    System.out.print(counter  +" ");
                    counter++;
                }
            }
            System.out.println();
            currentRow++;
        }
    }
}

Output

Enter the number of rows to print the pattern 
5
** Printing the pattern... **
1 
3 2 
4 5 6 
10 9 8 7 
11 12 13 14 15

Pattern 40:

package com.javainterviewpoint;

import java.util.Scanner;

public class Pattern40
{
    public static void main(String[] args) 
    { 
        int currentRow = 1;
        int counter = 1;
        
        // Create a new Scanner object
        Scanner scanner = new Scanner(System.in);
        
        // Get the number of rows from the user
        System.out.println("Enter the number of rows to print the pattern ");

        int rows = scanner.nextInt();
        
        System.out.println("** Printing the pattern... **");
        for (int i=1; i<= rows; i++)
        {
            if (i % 2 == 0) 
            {
                for (int j = 1; j<=i; j++)
                {
                    System.out.print(counter  +" ");
                    counter++;
                }
            }
            else
            {
                int reverse = currentRow + counter - 1;
                for (int j = 0; j<i; j++)
                {
                    System.out.print(reverse--  +" ");
                    counter++;
                }
            }
            System.out.println();
            currentRow++;
        }
    }
}

Output

Enter the number of rows to print the pattern 
5
** Printing the pattern... **
1 
2 3 
6 5 4 
7 8 9 10 
15 14 13 12 11

Pattern 41:

package com.javainterviewpoint;

import java.util.Scanner;

public class Pattern41
{
    public static void main(String[] args)
    {
        // Create a new Scanner object
        Scanner scanner = new Scanner(System.in);

        // Get the number of rows from the user
        System.out.println("Enter the number of rows to print the pattern ");

        int rows = scanner.nextInt();
        
        System.out.println("** Printing the pattern... **");
        
        for (int i = rows; i >= 1; i--)
        {
            for (int j = rows; j >= 1+rows-i; j--)
            {
                System.out.print(j);
            }
            
            for (int j= i*2 ; j < rows*2-1; j++)
            {
                System.out.print(" ");
            }
            
            for (int l = 1+rows-i; l <=rows; l++)
            {
                if(l!=1)
                    System.out.print(l);
            }
            System.out.println();
        }
        scanner.close();
    }
}

Output

Enter the number of rows to print the pattern 
5
** Printing the pattern... **
543212345
5432 2345
543   345
54     45
5       5

Pattern 42:

package com.javainterviewpoint;

import java.util.Scanner;
public class Pattern42
{
        public static void main(String[] args)
        {
            // Create a new Scanner object
            Scanner scanner = new Scanner(System.in);

            // Get the number of rows from the user
            System.out.println("Enter the number of rows to print the pattern ");

            int rows = scanner.nextInt();
            
            System.out.println("** Printing the pattern... **");
            
            for (int i = rows; i >= 1; i--)
            {
                for (int j = 1; j <= i; j++)
                {
                    System.out.print(j);
                }
                
                for (int j= i*2 ; j < rows*2-1; j++) 
                { 
                    System.out.print(" "); 
                } 
                for (int l = i; l >= 1; l--)
                {
                    if(l!=rows)
                        System.out.print(l);
                }
                System.out.println();
            }
            scanner.close();
        }
}

Output

Enter the number of rows to print the pattern 
5
** Printing the pattern... **
123454321
1234 4321
123   321
12     21
1       1

Pattern 43:

package com.javainterviewpoint;

import java.util.Scanner;

public class Pattern43
{
    public static void main(String[] args)
    {
        // Create a new Scanner object
        Scanner scanner = new Scanner(System.in);
        // Get the number of rows from the user
        System.out.println("Enter the number of rows to print the pattern ");
        int rows = scanner.nextInt();
        System.out.println("** Printing the pattern... **");

        // Top Half
        for (int i = 1; i <= rows; i++)
        {
            for (int j = 1; j <= i; j++)
            {
                System.out.print(j + " ");
            }
            for (int k = i - 1; k >= 1; k--)
            {
                System.out.print(k + " ");
            }
            System.out.println();
        }
        
        // Bottom Half
        for (int i = rows-1; i >= 1; i--)
        {
            for (int j = 1; j <= i; j++)
            {
                System.out.print(j + " ");
            }
            for (int k = i - 1; k >= 1; k--)
            {
                System.out.print(k + " ");
            }
            System.out.println();
        }
    }
}

Output

Enter the number of rows to print the pattern 
5
** Printing the 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 3 2 1 
1 2 3 2 1 
1 2 1 
1

Pattern 44:

package com.javainterviewpoint;

import java.util.Scanner;

public class Pattern44
{
    public static void main(String[] args)
    {
        // Create a new Scanner object
        Scanner scanner = new Scanner(System.in);
        // Get the number of rows from the user
        System.out.println("Enter the number of rows to print the pattern ");
        int rows = scanner.nextInt();
        System.out.println("** Printing the pattern... **");

        // Top Half
        for (int i = 1; i <= rows; i++)
        {
            int temp = i;
            for (int j = 1; j <= i; j++)
            {
                System.out.print(temp + " ");
                temp = temp + 1;
            }
            temp = temp - 2;
            for (int k = i - 1; k >= 1; k--)
            {
                System.out.print(temp + " ");
                temp = temp - 1;
            }
            System.out.println();
        }

        // Bottom Half
        for (int i = rows - 1; i >= 1; i--)
        {
            int temp = i;
            for (int j = 1; j <= i; j++)
            {
                System.out.print(temp + " ");
                temp = temp + 1;
            }
            temp = temp - 2;
            for (int k = i - 1; k >= 1; k--)
            {
                System.out.print(temp + " ");
                temp = temp - 1;
            }
            System.out.println();
        }
    }
}

Output

Enter the number of rows to print the pattern 
5
** Printing the pattern... **
1 
2 3 2 
3 4 5 4 3 
4 5 6 7 6 5 4 
5 6 7 8 9 8 7 6 5 
4 5 6 7 6 5 4 
3 4 5 4 3 
2 3 2 
1

Pattern 45:

package com.javainterviewpoint;

import java.util.Scanner;

public class Pattern45
{
    public static void main(String[] args)
    {
        // Create a new Scanner object
        Scanner scanner = new Scanner(System.in);
        // Get the number of rows from the user
        System.out.println("Enter the number of rows to print the pattern ");
        int rows = scanner.nextInt();
        System.out.println("** Printing the pattern... **");
        int temp = 1;
        for (int i = 1; i <= rows; i++)
        {
            for (int k = 1; k <= i; k++)
            {
                System.out.print(temp + " ");
            }
            temp++;
            System.out.println();
        }

        for (int i = rows - 1; i >= 1; i--)
        {
            for (int k = i; k >= 1; k--)
            {
                System.out.print(temp + " ");
            }
            temp++;
            System.out.println();
        }
    }
}

Output

Enter the number of rows to print the pattern 
5
** Printing the pattern... **
1 
2 2 
3 3 3 
4 4 4 4 
5 5 5 5 5 
6 6 6 6 
7 7 7 
8 8 
9

Pattern 46:

package com.javainterviewpoint;

import java.util.Scanner;

public class Pattern46
{
    public static void main(String[] args)
    {
        // Create a new Scanner object
        Scanner scanner = new Scanner(System.in);
        // Get the number of rows from the user
        System.out.println("Enter the number of rows to print the pattern ");
        int rows = scanner.nextInt();
        System.out.println("** Printing the pattern... **");
        for (int i = 1; i <= rows; i++)
        {
            for (int k = i; k >= 1; k--)
            {
                System.out.print(k + " ");
            }
            for (int l = 2; l <= i; l++)
            {
                System.out.print(l + " ");
            }
            System.out.println();
        }

        for (int i = rows - 1; i >= 1; i--)
        {
            for (int k = i; k >= 1; k--)
            {
                System.out.print(k + " ");
            }
            for (int l = 2; l <= i; l++)
            {
                System.out.print(l + " ");
            }
            System.out.println();
        }
    }
}

Output

Enter the number of rows to print the pattern 
5
** Printing the pattern... **
1 
2 1 2 
3 2 1 2 3 
4 3 2 1 2 3 4 
5 4 3 2 1 2 3 4 5 
4 3 2 1 2 3 4 
3 2 1 2 3 
2 1 2 
1

Pattern 47:

package com.javainterviewpoint;

import java.util.Scanner;

public class Pattern47
{
    public static void main(String[] args)
    {
        // Create a new Scanner object
        Scanner scanner = new Scanner(System.in);
        // Get the number of rows from the user
        System.out.println("Enter the number of rows to print the pattern ");
        int rows = scanner.nextInt();
        System.out.println("** Printing the pattern... **");
        for (int i = 1; i <= rows; i++)
        {
            for (int j = rows; j > i; j--)
            {
                System.out.print(" ");
            }
            int val1 = 1;
            for (int k = 1; k <= i; k++)
            {

                System.out.print(val1 + " ");
                val1 = val1 * 2;
            }
            val1 = val1 / 4;
            for (int l = i - 1; l >= 1; l--)
            {
                System.out.print(val1 + " ");
                val1 = val1 / 2;
            }
            System.out.println();
        }
    }
}

Output

Enter the number of rows to print the pattern 
5
** Printing the pattern... **
    1 
   1 2 1 
  1 2 4 2 1 
 1 2 4 8 4 2 1 
1 2 4 8 16 8 4 2 1

Pattern 48:

package com.javainterviewpoint;

import java.util.Scanner;

public class Pattern48
{
    public static void main(String[] args)
    {
        // Create a new Scanner object
        Scanner scanner = new Scanner(System.in);
        // Get the number of rows from the user
        System.out.println("Enter the number of rows to print the pattern ");
        int rows = scanner.nextInt();
        System.out.println("** Printing the pattern... **");
        for (int i = rows; i >= 1; i--)
        {
            for (int j = i; j <= rows; j++)
            {
                System.out.print(j + " ");
            }
            System.out.println();
        }
    }
}

Output

Enter the number of rows to print the pattern 
5
** Printing the pattern... **
5 
4 5 
3 4 5 
2 3 4 5 
1 2 3 4 5

Pattern 49:

package com.javainterviewpoint;

import java.util.Scanner;

public class Pattern49
{
    public static void main(String[] args)
    {
        // Create a new Scanner object
        Scanner scanner = new Scanner(System.in);
        // Get the number of rows from the user
        System.out.println("Enter the number of rows to print the pattern ");
        int rows = scanner.nextInt();
        System.out.println("** Printing the pattern... **");

        int temp = 2;

        for (int i = 1; i <= rows; i++)
        {
            for (int j = 1; j <= i; j++)
            {
                while (!isPrime(temp))
                {
                    temp++;
                }
                System.out.print(temp + " ");
                temp++;
            }
            System.out.println();
        }
    }

    public static boolean isPrime(int num)
    {
        boolean flag = false;
        for (int k = 2; k <= num / 2; k++)
        {

            if (num % k == 0)
            {
                flag = true;
                break;
            }
        }
        if (flag)
            return false;
        return true;
    }
}

Output

Enter the number of rows to print the pattern 
5
** Printing the pattern... **
2 
3 5 
7 11 13 
17 19 23 29 
31 37 41 43 47

Pattern 50:

package com.javainterviewpoint;

import java.util.Scanner;

public class Pattern50
{
	public static void main(String[] args)
	{
		// Create a new Scanner object
		Scanner scanner = new Scanner(System.in);
		// Get the number of rows from the user
		System.out.println("Enter the number of rows to print the pattern ");

		int rows = scanner.nextInt();
		System.out.println("** Printing the pattern... **");
		System.out.println("0");
		for (int i = rows; i >= 1; i--)
		{
			for (int j = i; j <= rows; j++) { System.out.print(j); } System.out.print("0"); for (int k = rows; k >= i; k--)
			{
				System.out.print(k);
			}
			System.out.println();
		}
	}
}

Output

Enter the number of rows to print the pattern 
5
** Printing the pattern... **
0
505
45054
3450543
234505432
12345054321

Pattern 51:

package com.javainterviewpoint;

import java.util.Scanner;

public class Pattern51
{
	public static void main(String[] args)
	{
		// Create a new Scanner object
		Scanner scanner = new Scanner(System.in);
		// Get the number of rows from the user
		System.out.println("Enter the number of rows to print the pattern ");

		int rows = scanner.nextInt();
		System.out.println("** Printing the pattern... **");
		int temp = 1;
		for (int i = 1; i <= rows; i++)
		{
			for (int j = 1; j <= i; j++)
			{
				System.out.print(temp + " ");
				temp++;
			}
			int temp1 = temp - 1;
			for (int k = 2; k <= i; k++)
			{
				System.out.print(--temp1 + " ");
			}
			System.out.println();
		}
	}
}

Output

Enter the number of rows to print the pattern 
5
** Printing the pattern... **
1 
2 3 2 
4 5 6 5 4 
7 8 9 10 9 8 7 
11 12 13 14 15 14 13 12 11 

Pattern 52:

package com.javainterviewpoint;

import java.util.Scanner;

public class Pattern52
{
	public static void main(String[] args)
	{
		// Create a new Scanner object
		Scanner scanner = new Scanner(System.in);
		// Get the number of rows from the user
		System.out.println("Enter the number of rows to print the pattern ");

		int rows = scanner.nextInt();
		System.out.println("** Printing the pattern... **");
		int temp = 1;
		for (int i = 1; i <= rows; i++) { for (int l = rows; l > i; l--)
			{
				System.out.print(" ");
			}
			for (int j = 1; j <= i; j++)
			{
				System.out.print(temp + " ");
				temp++;
			}
			int temp1 = temp - 1;
			for (int k = 2; k <= i; k++)
			{
				System.out.print(--temp1 + " ");
			}
			System.out.println();
		}
	}
}

Output

Enter the number of rows to print the pattern 
5
** Printing the pattern... **
    1 
   2 3 2 
  4 5 6 5 4 
 7 8 9 10 9 8 7 
11 12 13 14 15 14 13 12 11

Pattern 53:

package com.javainterviewpoint;

import java.util.Scanner;

public class Pattern53
{
	public static void main(String[] args)
	{
		// Create a new Scanner object
		Scanner scanner = new Scanner(System.in);
		// Get the number of rows from the user
		System.out.println("Enter the number of rows to print the pattern ");
		int rows = scanner.nextInt();
		int temp = 1;
		System.out.println("** Printing the pattern... **");

		for (int i = 1; i <= rows; i++) { for (int l = rows; l > i; l--)
			{
				System.out.print(" ");
			}
			for (int j = 1; j <= (i * 2 - 1); j++)
			{
				System.out.print((int) Math.pow(temp, 2) + " ");
				temp++;
			}
			System.out.println();
		}
	}
}

Output

Enter the number of rows to print the pattern 
4
** Printing the pattern... **
   1 
  4 9 16 
 25 36 49 64 81 
100 121 144 169 196 225 256

Pattern 54:

package com.javainterviewpoint;

import java.util.Scanner;

public class Pattern54
{
	public static void main(String[] args)
	{
		// Create a new Scanner object
		Scanner scanner = new Scanner(System.in);
		// Get the number of rows from the user
		System.out.println("Enter the number of rows to print the pattern ");

		int rows = scanner.nextInt();
		System.out.println("** Printing the pattern... **");
		int temp = 1;
		for (int i = 1; i <= rows; i++) { for (int l = rows; l > i; l--)
			{
				System.out.print(" ");
			}
			for (int j = 1; j <= i; j++)
			{
				if (temp < 10)
				{
					System.out.print(temp + " ");
					temp++;
				} else
				{
					temp = 0;
					System.out.print(temp + " ");
					temp++;
				}
			}
			int temp1 = temp - 1;
			for (int k = 2; k <= i; k++)
			{
				if (temp1 == 0)
				{
					temp1 = 10;
					System.out.print(--temp1 + " ");
				} else
				{
					System.out.print(--temp1 + " ");
				}
			}
			System.out.println();
		}
	}
}

Output

Enter the number of rows to print the pattern 
5
** Printing the pattern... **
    1 
   2 3 2 
  4 5 6 5 4 
 7 8 9 0 9 8 7 
1 2 3 4 5 4 3 2 1 

Pattern 55:

package com.javainterviewpoint;

import java.util.Scanner;

public class Pattern55
{
	public static void main(String[] args)
	{
		int currentRow = 1;
		int counter = 1;
		// Create a new Scanner object
		Scanner scanner = new Scanner(System.in);
		// Get the number of rows from the user
		System.out.println("Enter the number of rows to print the pattern ");
		int rows = scanner.nextInt();

		System.out.println("** Printing the pattern... **");
		for (int i = 1; i <= rows; i++) { for (int l = rows; l > i; l--)
			{
				System.out.print(" ");
			}
			if (i % 2 == 0)
			{
				int reverse = currentRow + counter - 1;
				for (int j = 0; j < i; j++)
				{
					System.out.print(reverse-- + " ");
					counter++;
				}
			} else
			{
				for (int j = 1; j <= i; j++)
				{
					System.out.print(counter + " ");
					counter++;
				}
			}
			System.out.println();
			currentRow++;
		}
	}
}

Output

Enter the number of rows to print the pattern 
5
** Printing the pattern... **
    1 
   3 2 
  4 5 6 
 10 9 8 7 
11 12 13 14 15

Pattern 56:

package com.javainterviewpoint;

import java.util.Scanner;

public class Pattern56
{
	public static void main(String[] args)
	{
		// Create a new Scanner object
		Scanner scanner = new Scanner(System.in);
		// Get the number of rows from the user
		System.out.println("Enter the number of rows to print the pattern ");
		int rows = scanner.nextInt();

		System.out.println("** Printing the pattern... **");

		for (int i = 1; i <= rows; i++)
		{
			for (int j = 1; j <= i; j++)
			{
				System.out.print((int) Math.pow(j, i) + " ");
			}
			System.out.println();
		}
	}
}

Output

Enter the number of rows to print the pattern 
4
** Printing the pattern... **
1 
1 4 
1 8 27 
1 16 81 256

Pattern 57:

package com.javainterviewpoint;

import java.util.Scanner;

public class Pattern57
{
	public static void main(String[] args)
    {
        // Create a new Scanner object
        Scanner scanner = new Scanner(System.in);

        // Get the number of rows from the user
        System.out.println("Enter the number of rows to print the pattern ");

        int rows = scanner.nextInt();
        System.out.println("** Printing the pattern... **");
        for (int i = 0; i < rows; i++)
        {
        	int num = 1;
            for (int j = 0; j <= i; j++)
            {
            	if(i ==0 || j ==0)
            		num = 1;
            	else
            		num = num * (i - j + 1)/ j;
                System.out.print(num + " ");
            }
            System.out.println();
        }
    }
}

Output

Enter the number of rows to print the pattern 
5
** Printing the pattern... **
1 
1 1 
1 2 1 
1 3 3 1 
1 4 6 4 1

Pattern 58:

package com.javainterviewpoint;

import java.util.Scanner;

public class Pattern58
{
	public static void main(String[] args)
    {
        // Create a new Scanner object
        Scanner scanner = new Scanner(System.in);

        // Get the number of rows from the user
        System.out.println("Enter the number of rows to print the pattern ");

        int rows = scanner.nextInt();
        System.out.println("** Printing the pattern... **");
        for (int i = 0; i <= rows; i++)
        {
        	int x = 0;
        	int y = 1;
        	System.out.print(y+" ");
            for (int j = 0; j < i; j++)
            {
            	int z = x + y;
            	System.out.print(z + " ");
            	x = y;
            	y = z;
            }
            System.out.println();
        }
    }
}

Output

Enter the number of rows to print the pattern 
5
** Printing the pattern... **
1 
1 1 
1 1 2 
1 1 2 3 
1 1 2 3 5 
1 1 2 3 5 8

I hope the above number pattern programs helped you. Do post the patterns which need to be added in the comments. Happy Learning !! 🙂

Filed Under: Java, Java Interview Tagged With: Diamond Pattern Programs, Java Interview Question, Java Interview Questions, Number Pattern, Number Pattern Programs, Pyramid Pattern Programs

Comments

  1. bibek sahoo says

    September 3, 2018 at 11:12 pm

    nice prograammm..keep posting such type of progrmm..

    Reply
    • Saranya says

      October 15, 2019 at 4:12 pm

      Hi ,
      Please anyone help me for this bellow program.

      8 80
      12 120 1200
      16 160 1600 16000

      Reply
      • javainterviewpoint says

        October 18, 2019 at 6:42 pm

        Here you go

        public class Test1
        {
        	public static void main(String[] args)
        	{
        		int start = 8;
        		for(int i=2; i<=4; i++)
        		{
        			int temp = start;
        			for(int j=1; j<=i; j++)
        			{
        				System.out.print(temp+" ");
        				temp = temp *10;
        			}
        			System.out.println();
        			start = start + 4;
        		}
        	}
        }
        Reply
  2. Amitabh Sinha says

    September 5, 2018 at 10:41 pm

    1
    2 6
    3 7 10
    4 8 11 13

    Reply
    • javainterviewpoint says

      September 9, 2018 at 12:45 pm

      Have added your pattern – Pattern 27

      Reply
  3. Sarthak says

    September 25, 2018 at 12:51 am

    Plz help me out by this program wirhin 9 O clock Today,
    #####
    ####
    ###
    ##
    #

    Reply
    • javainterviewpoint says

      September 25, 2018 at 1:05 pm

      Here you go
      for(int i=5; i>=1; i–){
      for(int j=i; j>=1; j–){
      System.out.print(“#”);
      }
      System.out.println();
      }

      Reply
  4. javainterviewpoint says

    September 25, 2018 at 9:34 pm

    Have added your pattern – Pattern 28

    Reply
  5. Jyothi says

    October 22, 2018 at 10:41 am

    Sir can you please post the code for this:
    1
    2 9
    3 8 10
    4 7 11 14
    5 6 12 13 15

    Reply
    • javainterviewpoint says

      October 25, 2018 at 10:30 pm

      Have added your pattern – Pattern 29

      Reply
  6. Deblina Sarkar says

    October 22, 2018 at 1:00 pm

    Plz help me out to do this program…..
    5 5 5 5 5
    5 4 4 4 4
    5 4 3 3 3
    5 4 3 2 2
    5 4 3 2 1

    Reply
    • javainterviewpoint says

      October 25, 2018 at 10:30 pm

      Have added your pattern – Pattern 31

      Reply
  7. Arpitha D says

    October 26, 2018 at 4:55 pm

    1
    3*2
    6*5*4
    10*9*8*7

    plz help to get this output

    Reply
    • javainterviewpoint says

      October 28, 2018 at 9:07 pm

      Here you go

      int j, n=5, k = 0;
      
              for (int i = 1; i <= n; i++)
              {
                  if (i % 2 != 0)
                  {
                      for (j = k + 1; j < k + i; j++)
                      {
                          System.out.print(j + "*");
                      }
                      System.out.println(j++);
                      k = j;
                  }
      
                  else
                  {
                      k = k + i - 1;
                      for (j = k; j > k - i + 1; j--)
                      {    
                          System.out.print(j + "*");
                      }
                      System.out.println(j);
                  }
              }
      Reply
  8. Haripriya says

    November 20, 2018 at 1:51 pm

    5
    4 5 4
    3 4 5 4 3
    2 3 4 5 4 3 2
    1 2 3 4 5 4 3 2 1
    2 3 4 5 4 3 2
    3 4 5 4 3
    4 5 4
    5
    Sir, can you please post the code for the above output pattern?

    Reply
    • javainterviewpoint says

      November 21, 2018 at 11:19 pm

      Have added your pattern – Pattern 33

      Reply
  9. Haripriya says

    November 20, 2018 at 1:54 pm

    1
    1 2 3
    1 2 3 5
    1 2 3 5 8
    1 2 3 5 8 13

    Sir, can you please post the code the above output pattern?

    Reply
    • javainterviewpoint says

      November 21, 2018 at 11:22 pm

      Here you go

      for (int i=1; i<=5;i++)
              {
                  int c = 0;
                  int a = 0;
                  int b = 1;
                          
                  for(int j=1; j<=i; j++)
                  {
                      c = a + b;
                      System.out.print(c+" ");
                      a = b;
                      b = c;
                  }
                  if (i!=1)
                      System.out.print(a + c);
                  System.out.println();
              }
      Reply
  10. Kumar ashutosh says

    November 21, 2018 at 8:49 am

    9
    7 9
    5 7 9
    3 5 7 9
    1 3 5 7 9

    Reply
    • javainterviewpoint says

      November 21, 2018 at 11:58 pm

      Here you go

      for(int i=0; i<5; i++)
      {
            int temp= 5 * 2 -1;
            temp = temp - (i*2);
            for(int j=0;j<=i;j++)
            {
                System.out.print(temp+" ");
                temp = temp+2;
            }
            System.out.println();
      }
      Reply
  11. Haripriya says

    November 23, 2018 at 7:21 pm

    Sir, can you please post the code the below output pattern?
    5
    4 5 4
    3 4 5 4 3
    2 3 4 5 4 3 2
    1 2 3 4 5 4 3 2 1
    2 3 4 5 4 3 2
    3 4 5 4 3
    4 5 4
    5

    Reply
  12. Haripriya says

    November 24, 2018 at 12:27 pm

    Sorry sir, I have given the wrong pattern. Actually, I need the output for the pattern given below. Thanks in advance.
    5
    4 5 4
    3 4 5 4 3
    2 3 4 5 4 3 2
    1 2 3 4 5 4 3 2 1
    2 3 4 5 4 3 2
    3 4 5 4 3
    4 5 4
    5

    Reply
  13. Abdinasir Ismail Ali says

    December 5, 2018 at 2:01 am

    Sir can you help me the code for this
    *
    **
    *
    ****
    *
    ******
    Please

    Reply
    • javainterviewpoint says

      December 5, 2018 at 10:47 am

      for( int i=1; i<=6; i++) { if(i%2!=0) System.out.print("*"); else { for(int j=1; j<=i; j++) System.out.print("*"); } System.out.println(); }

      Reply
  14. Shahi says

    December 16, 2018 at 12:26 pm

    1 2 3 4 5
    2 2 3 4 5
    3 3 3 4 5
    4 4 4 4 5
    5 5 5 5 5
    how create this type of pattern pls help sir

    Reply
    • javainterviewpoint says

      December 19, 2018 at 11:27 am

      Here you go
      for(int i=1; i<=5;i++) { for(int j=1;j<=5; j++) { if(j<=i) System.out.print(i); else System.out.print(j); } System.out.println(); }

      Reply
  15. Tejal says

    December 23, 2018 at 12:24 pm

    2
    3 5
    7 11 13
    17 19 23 29
    31 37 41 43 47 Sir, can you please post the code for the above output pattern?

    Reply
    • javainterviewpoint says

      December 27, 2018 at 9:08 am

      Here you go
      static int prime = 2;

      public static void main(String[] args)
      {
      for (int i = 1; i <= 5; i++) { for (int j = 1; j <= i; j++) { boolean flag = checkPrime(prime); while(flag) { ++prime; flag = checkPrime(prime); if(!flag) break; } System.out.print(prime+" "); prime++; } System.out.println(); } } public static boolean checkPrime(int num) { boolean flag = false; for (int i = 2; i <= num / 2; ++i) { if (num % i == 0) { flag = true; break; } } return flag; }

      Reply
  16. Harshit says

    January 12, 2019 at 9:20 am

    Plzzz do this
    *
    *#
    *#*
    *#*#
    *#*#*

    Reply
    • javainterviewpoint says

      January 23, 2019 at 5:37 pm

      Here you go
      public static void main(String[] args)
      {
      int n=5;

      for(int i = 0; i < 5; i++) { for(int j = 0; j <= i; j++) { if(j % 2 == 0) System.out.print("*"); else System.out.print("#"); } System.out.print("\n"); } }

      Reply
  17. heerne says

    January 23, 2019 at 9:29 pm

    need this pattern please
    1
    4 1
    9 4 1
    16 9 4 1
    25 16 9 4 1

    Reply
    • javainterviewpoint says

      January 25, 2019 at 1:45 pm

      Here you go

      public static void main(String[] args)
      {
      for (int i = 1;i <= 5;i++) { for (int j = i;j >= 1;j--)
      {
      System.out.print(j * j + " ");
      }

      System.out.println();
      }
      }

      Reply
      • Dhanya Vijayan says

        April 2, 2020 at 9:09 pm

        Can anyone help me with the code
        1
        1 12
        1 12 123
        1 12 123 1234
        1 12 123 1234 12345

        Reply
        • javainterviewpoint says

          April 3, 2020 at 3:09 pm

          Here you go

          public class Pattern
          {
              public static void main(String[] args)
              {
                  for(int i=1; i<=5; i++)
                  {
                      for(int j=1; j<=i; j++)
                      {
                         for(int k=1; k<=j;k++)
                         {
                             System.out.print(k);
                         }
                         System.out.print(" ");
                      }
                      System.out.println();
                  }
                  
              }
          }
          Reply
  18. Abhyankar says

    January 26, 2019 at 10:45 pm

    1***
    12**
    123*
    1234
    How to do this?

    Reply
    • javainterviewpoint says

      January 27, 2019 at 10:07 am

      Here you go
      public static void main(String[] args)
      {
      for (int i = 1;i <= 4;i++) { for (int j=1; j<=i; j++) { System.out.print(j+" "); } for (int k=3; k>=i; k--)
      {
      System.out.print("* ");
      }
      System.out.println();
      }
      }

      Reply
  19. Raj Gupta says

    February 5, 2019 at 7:11 pm

    1
    3 1
    5 3 1
    7 5 3 1
    9 5 7 3 1
    Help me out this pattern

    Reply
    • javainterviewpoint says

      February 16, 2019 at 10:47 pm

      Here you go
      public static void main(String[] args)
      {
      for (int i = 1;i <= 5;i++) { int temp = i*2 -1; for (int j = 1; j <=i ; j++) { System.out.print(temp+" "); temp= temp -2; } System.out.println(); } }

      Reply
  20. Asish Kumar says

    February 12, 2019 at 11:45 pm

    how to print following this pattern using for loop
    1
    2
    3
    4
    5

    Reply
    • javainterviewpoint says

      February 16, 2019 at 10:53 pm

      Here you go
      public static void main(String[] args)
      {
      for (int i = 1;i <= 5;i++) { System.out.println(i); } }

      Reply
  21. kartik kumar verma says

    February 16, 2019 at 3:08 pm

    1
    2 3
    3 4 5
    4 5 6 7

    Reply
    • javainterviewpoint says

      February 16, 2019 at 10:52 pm

      Here you go
      public static void main(String[] args)
      {
      for (int i = 1;i <= 5;i++) { int temp = i; for (int j = 1; j <=i ; j++) { System.out.print(temp+" "); temp= temp +1; } System.out.println(); } }

      Reply
  22. Renuka says

    February 22, 2019 at 10:44 am

    *****
    0000
    ***
    00
    *
    pls solve this

    Reply
    • javainterviewpoint says

      February 22, 2019 at 6:25 pm

      Here you go
      public static void main(String[] args)
      {
      for (int i = 1; i <= 5; i++) { for (int j = 5; j >= i; j--)
      {
      if (i % 2 == 0)
      {
      System.out.print("0 ");
      } else
      {
      System.out.print("* ");
      }
      }

      System.out.println();
      }
      }

      Reply
  23. AbirJash says

    February 23, 2019 at 12:31 am

    Sir can you help me
    1
    1 1
    1 0 1
    1 0 0 1
    1 0 0 0 1

    Reply
    • javainterviewpoint says

      February 23, 2019 at 12:51 pm

      Here you go
      public static void main(String[] args)
      {
      for (int i = 1; i <= 5; i++) { for (int j = 1; j <= i; j++) { if(j ==1 || j == i) System.out.print("1"); else System.out.print("0"); } System.out.println(); }

      Reply
  24. AJAY says

    March 16, 2019 at 10:39 am

    please TELL how to print this patttern
    A
    A B A
    A B C B C
    A B C D C B A
    A B C D E D C B A

    Reply
    • javainterviewpoint says

      March 16, 2019 at 3:46 pm

      Check out the Pattern 14 of Alphabet Pattern Program
      https://www.javainterviewpoint.com/alphabet-pattern-program/

      Reply
  25. Shreya says

    March 17, 2019 at 11:30 am

    could you help me with this patter
    1 3 5 7 9
    3 5 7 9 1
    5 7 9 1 3
    7 9 1 3 5
    9 1 3 5 7

    Reply
    • javainterviewpoint says

      March 17, 2019 at 4:10 pm

      Have added your pattern – Pattern 36

      Reply
      • Shreya says

        March 17, 2019 at 8:39 pm

        thank you so much sir.

        Reply
  26. Vineesha Balne says

    March 31, 2019 at 1:18 am

    Hi Sir,

    Can you please let me know how to print this pattern?

    1
    12
    123
    1234
    12345

    Reply
    • javainterviewpoint says

      March 31, 2019 at 11:52 am

      Here you go

      public class Pattern
      {
          public static void main(String[] args)
          {
              for (int i=1; i<=5;i++)
              {
                  for(int j=1; j<=i; j++)
                  {
                      System.out.print(j);
                  }
                  System.out.println();
              }
          }
      }
      
      Reply
  27. SIBA says

    March 31, 2019 at 6:19 pm

    write a program in java to accept a string from the user . pass the string to a function change (string str) which displays the first character of each word after changing the case,sample input:- delhi public school
    Out Put:-D
    P
    S

    Reply
    • javainterviewpoint says

      March 31, 2019 at 6:59 pm

      Here you go

      import java.util.Scanner;
      
      public class TitleCase
      {
          public static void main(String[] args)
          {
              boolean flag = true;
              Scanner scanner = new Scanner(System.in);
              
              System.out.println("Enter the String which needs to be converted to TitleCase");
              String text = scanner.nextLine();
      
      
              for (char ch : text.toCharArray()) 
              {
                  if (Character.isSpaceChar(ch)) 
                  {
                      flag = true;
                  } 
                  else if (flag) 
                  {
                      ch = Character.toUpperCase(ch);
                      flag = false;
                      System.out.println(ch);
                  }
              }
          }
      }
      
      Reply
  28. Mithal says

    April 7, 2019 at 10:36 am

    Can u. Please let me know how to print this program ?
    *1234
    1*123
    12*12
    123*1

    Reply
    • javainterviewpoint says

      April 7, 2019 at 2:37 pm

      Here you go

      public class Pattern
      {
          public static void main(String[] args)
          {
              int flag = 0;
              int count = 0;
              
              for (int i= 1; i < 5; i++)
              {
                  flag = i;
                  count = 0;
                  
                  for (int j=1; j < 5; j++)
                  {
                      count ++;
                     if(flag == j)
                     {
                         System.out.print("* ");
                         j = 0;
                         flag = 0;
                     }
                     else
                     {
                         System.out.print(j+" ");
                     }
                      if (count == 5)
                          break;
                  }
                  System.out.println();
              }
          }
      }
      Reply
  29. Saiesh says

    April 10, 2019 at 1:14 pm

    *
    **
    ***
    ****
    *****
    ******
    ******
    *****
    ****
    ***
    **
    *
    Please print above pattern for n=6. And please tell us how can we improve ourselves in such problems. What do we practice to achieve your level Sir.

    Reply
    • javainterviewpoint says

      April 10, 2019 at 3:08 pm

      I have created a separate collection for star pattern programs
      https://www.javainterviewpoint.com/star-pattern-programs-in-java/

      The pattern which you have asked is at Pattern 9

      Just keep practicing for loops and you will be stronger soon:)

      Reply
  30. Mahesh says

    April 18, 2019 at 10:43 pm

    1
    1*
    1*3
    1*3*
    1*3*5

    Code for this please

    Reply
    • javainterviewpoint says

      April 19, 2019 at 12:27 pm

      Here you go

      public class Pattern
      {
      	public static void main(String[] args)
      	{
      		for(int i=1; i<=5; i++)
      		{
      			for(int j=1; j<=i; j++)
      			{
      				if(j%2 == 0)
      					System.out.print("* ");
      				else
      					System.out.print(j+" ");
      			}
      			System.out.println();
      		}
      	}
      }
      Reply
  31. Padmashekara Pathyare Shetty says

    April 22, 2019 at 6:10 pm

    Can you please help me to print this program ?
    abcdedcba
    abcdcba
    abcba
    aba
    a

    Please by tomorrow afternoon

    Reply
    • javainterviewpoint says

      April 27, 2019 at 6:50 pm

      Added your pattern in the Alphabet Pattern – Pattern 28

      Reply
  32. Padmashekara Pathyare Shetty says

    April 22, 2019 at 6:13 pm

    Can you please help me to print this pattern?
    ABCDE
    BCDEF
    CDEFG
    DEFGH

    Please by tomorrow afternoon

    Reply
    • javainterviewpoint says

      April 27, 2019 at 6:50 pm

      Added your pattern in the Alphabet Pattern Post – Pattern 27

      Reply
  33. Padmashekara Pathyare Shetty says

    April 22, 2019 at 6:21 pm

    Write a program in Java to accept a String in upper case and print the words which have at least a pair of consecutive letters
    sample input: MODEM IS AN ELECTRONIC DEVICE
    sample output : MODEM
    DEVICE
    Please sir help me wit this question

    Reply
    • javainterviewpoint says

      April 27, 2019 at 6:49 pm

      Can you please brief a little more, you want consecutive characters or is it fine to display word which has characters occurring more than once

      Reply
      • Padmashekara Shetty says

        July 18, 2019 at 5:49 pm

        I want the consecutive characters
        Eg : moDEm
        DEvice

        No. Of words : 2

        Reply
        • javainterviewpoint says

          July 20, 2019 at 9:48 am

          It was already there in the Number pattern program, follow the below link
          https://www.javainterviewpoint.com/number-pattern-programs-in-java/#comment-25725

          Reply
  34. mahesh says

    April 23, 2019 at 12:33 pm

    Code for this pattern
    *
    123
    *****
    1234567

    Reply
  35. Mahesh says

    April 23, 2019 at 12:49 pm

    54321
    4321
    321
    21
    1

    This pattern also please

    Reply
    • javainterviewpoint says

      April 27, 2019 at 1:58 pm

      Here you go

      public class Pattern
      {
          public static void main(String[] args)
          {
              for (int i = 1; i <= 5; i++)
              {
                  for (int l = 5-i+1 ; l >= 1; l--)
                  {
                      System.out.print(l);
                  }
                  System.out.println();
              }
          }
      }
      Reply
  36. Srinivas says

    April 25, 2019 at 11:49 pm

    123454321
    1234321
    12321
    121
    1

    Write a program to reverse this pyramid

    Reply
    • javainterviewpoint says

      April 27, 2019 at 1:52 pm

      Here you go

      public class Pattern
      {
          public static void main(String[] args)
          {
              for (int i = 1; i <= 5; i++)
              {
                  for (int k = 1; k <= 5-i+1; k++)
                  {
                      System.out.print(k);
                  }
                  for (int l = 5 -i ; l >= 1; l--)
                  {
                      System.out.print(l);
                  }
                  System.out.println();
              }
          }
      }
      Reply
  37. Rajat goel says

    May 7, 2019 at 7:04 am

    #
    #1#
    #23#
    #456#

    Reply
    • javainterviewpoint says

      May 7, 2019 at 9:36 am

      Here you go

      public class Pattern
      {
          public static void main(String[] args)
          {
              int flag = 1;
              for (int i = 1; i <= 5; i++)
              {
                  for (int j = 1 ; j <= i; j++)
                  {
                      if(j == 1)
                      {
                          System.out.print("#");
                      }
                      else
                      {
                          if(j == i)
                          {
                              System.out.print(flag+"#");
                          }
                          else
                          {
                              System.out.print(flag);
                          }
                          flag++;
                      }
                  }
                  System.out.println();
              }
          }
      }
      Reply
  38. Raj says

    May 20, 2019 at 6:43 pm

    1
    3. 5
    7. 9. 11
    13 15. 17. 19

    Reply
    • javainterviewpoint says

      May 20, 2019 at 9:50 pm

      Do you need the dots as well.. If yes why some of the dots are missing after the numbers ? is there any logic behind it?

      Reply
  39. Pradip Kumar Das says

    May 22, 2019 at 4:54 am

    Please write the BlueJ code for the following pattern by today.
    ABCDE
    ABCDA
    ABCAB
    ABABC
    AABCD

    Reply
    • javainterviewpoint says

      May 22, 2019 at 9:25 pm

      Here you go

      public static void main(String[] args)
          {
              System.out.println("** Printing the pattern... **");
              for (int i = 0; i < 5; i++)
              {
                  int alphabet = 65;
                  for (int j = i; j < 5; j++)
                  {
                      System.out.print((char) (alphabet));
                      alphabet ++;
                  }
                  
                  alphabet = 65;
                  
                  for (int k = 1; k <= i; k++)
                  {
                      System.out.print((char) (alphabet));
                      alphabet ++;
                  }
                  System.out.println();
              }
          }
      Reply
  40. Rak says

    May 27, 2019 at 6:42 pm

    1
    0 1
    0 1 0
    1 0 1 0

    Reply
    • javainterviewpoint says

      May 28, 2019 at 6:14 pm

      Here you go

      public class Pattern
      {
          public static void main(String[] args)
          {
              for (int i = 1; i <= 5; i++)
              {
                  for (int j = 1 ; j <= i; j++)
                  {
                      if(((i + j) % 2) == 0)
                          System.out.print("1"); 
                      else
                          System.out.print("0");
                  }
                  System.out.println();
              }
          }
      }
      Reply
  41. mahesh says

    May 27, 2019 at 6:46 pm

    I
    I Like
    I Like Very
    I Like Very Much
    I Like Very Much Java

    Reply
    • javainterviewpoint says

      May 28, 2019 at 6:20 pm

      Here you go

      public class Pattern
      {
          public static void main(String[] args)
          {
              String str = "I Like Very Much Java";
              String[] strArr = str.split(" ");
              
              for(int i=0;i< strArr.length;i++)
              {
                  for(int j=0;j<=i;j++)
                  {
                      System.out.print(strArr[j]+" ");
                  }
                 System.out.println();
              }
          }
      }
      Reply
  42. Anas Siddiqui says

    May 30, 2019 at 5:28 pm

    Plzzz help me out for this pattern ….plzzz —
    12345
    2345
    345
    45
    5
    45
    345
    2345
    12345

    Reply
    • javainterviewpoint says

      May 30, 2019 at 7:36 pm

      Here you go

      public static void main(String[] args)
      	{
      		// Create a new Scanner object
      		Scanner scanner = new Scanner(System.in);
      
      		// Get the number of rows from the user
      		System.out.println("Enter the number of rows to print the pattern ");
      
      		int rows = scanner.nextInt();
      		System.out.println("** Printing the pattern... **");
      		for (int i = 1; i <= rows; i++)
      		{
      			for (int k = i; k <= rows; k++)
      			{
      				System.out.print(k);
      			}
      			System.out.println();
      		}
      		for (int i = rows-1; i >= 1; i--)
      		{
      			for (int k = i; k <= rows; k++)
      			{	
      				System.out.print(k);
      			}
      			System.out.println();
      		}
      	}
      Reply
  43. Nihar says

    May 30, 2019 at 11:03 pm

    please help me with this program
    Write a program to input a sentence.convert the sentence into upper case.display
    the words along with frequency of the words which have at least a pair of consecutive letters
    sample input :MODEM IS AN ELECTRONIC DEVICE
    sample output:MODEM
    DEVICE
    NO OF WORDS CONTAINING CONSECUTIVE LETTERS : 2

    Reply
    • javainterviewpoint says

      May 31, 2019 at 10:55 am

      Here you go

      public static void main(String[] args)
      	{
      		Scanner scanner = new Scanner(System.in);
      		String s;
      		int count = 0;
      		System.out.println("enter a string");
      		s = scanner.nextLine().toUpperCase();
      
      		String arr[] = s.split("\\s");
      
      		for (int i = 0; i < arr.length; i++)
      		{
      			for (int j = 0; j < arr[i].length(); j++)
      			{
      				if (j == arr[i].length() - 1)
      					break;
      
      				if ((char) (arr[i].charAt(j) + 1) == arr[i].charAt(j + 1))
      				{
      					System.out.println(arr[i]);
      					count++;
      					break;
      				}
      			}
      		}
      		
      		System.out.println("NO OF WORDS CONTAINING CONSECUTIVE LETTERS : "+count);
      	}
      Reply
  44. Pintu says

    June 4, 2019 at 11:49 pm

    1
    234
    56789
    10111213141516

    Reply
    • javainterviewpoint says

      June 5, 2019 at 8:34 pm

      Here you go

      public static void main(String[] args)
      	{
      		// Create a new Scanner object
      		Scanner scanner = new Scanner(System.in);
      
      		// Get the number of rows from the user
      		System.out.println("Enter the number of rows to print the pattern ");
      
      		int rows = scanner.nextInt();
      		System.out.println("** Printing the pattern... **");
      		int count = 1;
      		for (int i = 0; i <= rows; i++)
      		{
      			for (int k = 1; k <= i*2+1; k++)
      			{
      				System.out.print(count);
      				count++;
      			}
      			System.out.println();
      		}
      	}
      Reply
  45. Parikshit Naskar says

    June 5, 2019 at 10:03 am

    Sir
    I face a Java problem. Please solve the problem .
    * * * *
    * * *
    * * * *
    * * *
    * * * *
    * * *
    * * * *

    Reply
    • javainterviewpoint says

      June 5, 2019 at 8:18 pm

      Added your pattern in the Alphabet Pattern Post – Pattern 35

      Reply
  46. VIGNESHWARAN says

    June 8, 2019 at 8:52 am

    1
    0 1
    1 0 1
    0 1 0 1
    1 0 1 0 1
    Help me

    Reply
    • javainterviewpoint says

      June 8, 2019 at 7:00 pm

      Here you go

      public static void main(String[] args)
          {
              for(int i=1; i<=5; i++)
              {
                  for(int j=i; j>=1; j--)
                  {
                      System.out.print(j%2+" ");
                  }
                  System.out.println();
              }
          }
      Reply
  47. Sachin Batra says

    June 8, 2019 at 11:50 am

    Explaining little more. first array digit is 6 so java program should print 6 asterisk then 2, 3 like this. And if its 9 then print nine starts. This should be bottom to top approach

    Reply
    • javainterviewpoint says

      June 15, 2019 at 11:22 am

      Can you brief me a little more on this, let me put my understanding first value is 6 so it should print 6 asterik from bottom to top, now what to 2,3 does there how it adds up space there? what is the logic behind it? also, post the pattern once again wrapped in <pre></pre> tag.

      Reply
      • Sachin batra says

        June 21, 2019 at 2:17 pm

        Yes asterik would print according to arrays value. first value is 6 it should print 6 asterik and so on…
        int ar[] = {3,2,4,5,6}

        *
        **
        ***
        * ***
        *****
        *****

        Reply
        • javainterviewpoint says

          June 21, 2019 at 4:07 pm

          Hope this is what you are looking for, the first column will have 3 asterisks, the second column will have 2 asterisks, the third column will have 4 asterisks and so on…

          public static void main(String[] args)
              {
                  int arr[] = {3,2,4,5,6};
                  
                  int max = 0;
                  
                  // Find the max element in the array
                  for(int i=0; i<arr.length; i++)
                  {
                      if(arr[i] > max)
                          max = arr[i];
                  }
                  // Create a 2D array
                  String[][] multi = new String[max][arr.length];
                  
                  for(int j=0; j<arr.length; j++)
                  {
                      int diff = max - arr[j];
                      for(int k=0; k<diff; k++)
                      {
                          multi[k][j] =" ";
                      }
                      for(int l=diff; l<max; l++)
                      {
                          multi[l][j] ="*";
                      }
                  }
                  
                  // Print the 2D array
                  for (int i = 0; i < multi.length; i++) 
                  {
                      for (int j = 0; j < multi[i].length; j++) 
                          System.out.print(multi[i][j] + " "); 
                  System.out.println();
                  }
              }
          Reply
  48. carol denvers says

    June 14, 2019 at 2:25 pm

    FIBONACCI PATTERN (PATTERN 4)

    0
    1 1
    2 3 5
    8 13 21 34

    Reply
    • javainterviewpoint says

      June 15, 2019 at 1:49 pm

      Here you go

      public static void main(String[] args)
          {
              int n = 4, val1 = 0, val2 = 1; int sum =0;
              for (int i = 1; i <= n; ++i)
              {
                  for(int j=1; j<=i; j++)
                  {
                      System.out.print(val1+" ");
                      sum = val1 + val2;
                      val1 = val2;
                      val2 = sum;
                  }
                  System.out.println();
              }
          }
      Reply
  49. ABREETH says

    June 25, 2019 at 5:40 pm

    HELLO SIR, PLEASE HELP ME TO SOLVE THIS

    *
    *
    * *
    * *
    * * *
    * *
    * *
    *
    *

    Reply
  50. ABREETH says

    June 25, 2019 at 7:27 pm

    Sir, i need a program for the same pattern 6 but the pyramid should be tilted 90 degree. kindly help me out

    Reply
    • javainterviewpoint says

      June 25, 2019 at 9:52 pm

      Here you go

      import java.util.Scanner;
      
      public class Pattern
      {
          public static void main(String[] args)
          {
              // Create a new Scanner object
              Scanner scanner = new Scanner(System.in);
              // Get the number of rows from the user
              System.out.println("Enter the number of rows needed in the pattern ");
              int rows = scanner.nextInt();
              System.out.println("** Printing the pattern... **");
              
              // Top Half
              for (int i = 1; i <= rows; i++)
              {
                  if (i % 2 != 0)
                  {
                      for (int j = 1; j <= i; j++)
                      {
                          if (j % 2 != 0)
                          {
                              System.out.print("* ");
                          } else
                          {
                              System.out.print("  ");
                          }
                      }
                      System.out.println();
                  } else
                  {
                      for (int j = 1; j <= i; j++)
                      {
                          if (j % 2 != 0)
                          {
                              System.out.print("  ");
                          } else
                          {
                              System.out.print("* ");
                          }
                      }
                      System.out.println();
                  }
              }
              // Bottom Half
              for (int i = rows - 1; i >= 1; i--)
              {
                  if (i % 2 != 0)
                  {
                      for (int j = 1; j <= i; j++)
                      {
                          if (j % 2 != 0)
                          {
                              System.out.print("* ");
                          } else
                          {
                              System.out.print("  ");
                          }
                      }
                      System.out.println();
                  } else
                  {
                      for (int j = 1; j <= i; j++)
                      {
                          if (j % 2 != 0)
                          {
                              System.out.print("  ");
                          } else
                          {
                              System.out.print("* ");
                          }
                      }
                      System.out.println();
                  }
              }
          }
      }
      Reply
  51. anonymous says

    June 26, 2019 at 2:00 pm

    sir please do pattern 38 upside down

    Reply
    • javainterviewpoint says

      June 26, 2019 at 10:44 pm

      Here you go

      import java.util.Scanner;
      
      public class Pattern
      {
          public static void main(String[] args)
          {
              // Create a new Scanner object
              Scanner scanner = new Scanner(System.in);
      
              // Get the number of rows from the user
              System.out.println("Enter the number of rows to print the pattern ");
      
              int rows = scanner.nextInt();
              
              System.out.println("** Printing the pattern... **");
              
              for (int i = rows; i >= 1; i--)
              {
                  for (int j = 1; j <= i; j++)
                  {
                      System.out.print(j);
                  }
                  
                  for (int j= i*2 ; j < rows*2; j++) 
                  { 
                      System.out.print(" "); 
                  } 
                  for (int l = i; l >= 1; l--)
                  {
                      System.out.print(l);
                  }
                  System.out.println();
              }
              scanner.close();
          }
      }
      Reply
  52. anonymous says

    June 26, 2019 at 2:03 pm

    Sir please do this pattern

    ABCD1
    BCD12
    CD123
    D1234

    Reply
    • javainterviewpoint says

      June 26, 2019 at 10:45 pm

      Your pattern

      import java.util.Scanner;
      
      public class Pattern
      {
          public static void main(String[] args) 
          { 
              // Create a new Scanner object 
              Scanner scanner = new Scanner(System.in); 
              // Get the number of rows from the user 
              System.out.println("Enter the number of rows needed in the pattern "); 
              int rows = scanner.nextInt(); 
              System.out.println("** Printing the pattern... **");
              
              int alphabet = 65;
              
              for(int i=0; i<rows; i++)
              {
                  for(int j=i; j<rows; j++)
                  {
                      System.out.print((char)(alphabet+j));
                  }
                  for(int k=0; k <= i; k++)
                  {
                      System.out.print(k+1);
                  }
                  
                  System.out.println();
              }
          }
      }
      Reply
  53. vineeth says

    June 26, 2019 at 2:04 pm

    Sir i need help in this pattern

    1
    2 4
    1 3 5
    2 4 6 8
    1 3 5 7 9

    Reply
    • javainterviewpoint says

      June 26, 2019 at 10:46 pm

      Below goes the pattern

      import java.util.Scanner;
      
      public class Pattern
      {
          public static void main(String[] args) 
          { 
              // Create a new Scanner object 
              Scanner scanner = new Scanner(System.in); 
              // Get the number of rows from the user 
              System.out.println("Enter the number of rows needed in the pattern "); 
              int rows = scanner.nextInt(); 
              System.out.println("** Printing the pattern... **");
              
              for(int i=1; i<=rows; i++)
              {
                  int temp =1;
                  if(i % 2 ==0)
                      temp =2;    
                  for(int j=1; j<=i; j++)
                  {
                      System.out.print(temp+" ");
                      temp +=2;
                  }
                  System.out.println();
              }
          }
      }
      Reply
  54. anonymous says

    June 27, 2019 at 12:28 pm

    Sir please do this for me.thank you
    1
    2 2
    3 3 3
    4 4 4 4

    Reply
    • anonymous says

      June 27, 2019 at 4:34 pm

      Sir please solve this in the form of a triangle

      Reply
    • javainterviewpoint says

      June 28, 2019 at 11:41 am

      Take Pattern 6 of Number Pattern Program and modify the third loop (k loop) instead of printing k print i
      Just change System.out.print(k + ” “); to System.out.print(i + ” “);

      Reply
  55. anonymous says

    June 28, 2019 at 12:12 am

    Sir please do pattern 2 in the form of a triangle

    Reply
  56. gajju says

    July 4, 2019 at 2:59 pm

    12345
    12341
    12312
    12123
    11234

    pls help me for this pattern

    Reply
    • javainterviewpoint says

      July 4, 2019 at 3:47 pm

      Here you go

      public class Pattern
      {
      	public static void main(String[] args)
      	{
      	    for(int i=1; i<=5; i++)
      	    {
      	        int temp = 1;
      	        for(int j=5; j>=i; j--)
      	        {
      	            System.out.print(temp);
      	            temp++;
      	        }
      	        for(int k=1; k<=i-1; k++)
      	        {
      	            if(i!=1)
      	                System.out.print(k);
      	        }
      	        System.out.println();
      	    }
      	}
      }
      Reply
  57. Meghna says

    July 11, 2019 at 9:35 pm

    11111
    22222
    33333
    444444
    55555
    Sir can you help me with this pattern…

    Reply
    • javainterviewpoint says

      July 11, 2019 at 9:46 pm

      Here you go

      public class Pattern
      {
      	public static void main(String[] args)
      	{
      		for(int i=1; i<=5;i++)
      		{
      			for(int j=1; j<=5; j++)
      			{
      				System.out.print(i);
      			}
      			System.out.println();
      		}
      	}
      }
      Reply
  58. Pheonix says

    July 24, 2019 at 1:34 pm

    Hi, I need something to resemble a snake pattern like this.
    1 2 3 4 5
    10 9 8 7 6
    11 12 13 14 15
    20 19 18 17 16

    Reply
    • javainterviewpoint says

      July 24, 2019 at 8:12 pm

      Here you go

      public class Pattern
      {
      	public static void main(String[] args)
      	{
      		int val = 1;
      		int temp = 0;
      		int rows = 4;
      		int cols = 5;
      		for (int i = 1; i <= rows; i++)
      		{
      			if (i % 2 == 0)
      			{
      				temp = cols - 1 + val;
      			}
      			for (int j = 1; j <= cols; j++)
      			{
      				if (i % 2 != 0)
      				{
      					System.out.print(val++ + " ");
      				} else
      				{
      					System.out.print(temp-- + " ");
      					val++;
      				}
      			}
      			System.out.println();
      		}
      	}
      }
      Reply
    • Hasnain says

      July 31, 2019 at 2:44 am

      Hi,I need someone to resolve patttern like this:-
      1
      3 5
      7 9 11
      1 3 5 7
      9 11 1 3 5
      7 9 11 1 3 5

      Reply
      • javainterviewpoint says

        August 3, 2019 at 12:02 pm

        Here you go

        public class Pattern
        {
            public static void main(String[] args)
            {
                int temp =1;
                for (int i = 1; i <= 6; i++)
                {
                    for(int j=1; j<=i; j++)
                    {
                        if(temp <=11)
                        {
                            System.out.print(temp+" ");
                            temp+=2;
                        }
                        else
                        {
                            temp =1;
                            System.out.print(temp+" ");
                            temp+=2;
                        }
                    }
                    System.out.println();
                }
            }
        }
        Reply
  59. Jainendra says

    July 30, 2019 at 7:41 pm

    sorry wrong pattern
    9 7 5 3 1
    7 5 3 1
    5 3 1
    3 1
    1

    Reply
    • javainterviewpoint says

      July 30, 2019 at 11:10 pm

      Here you go

      public class Pattern
      {
      	public static void main(String[] args)
      	{
      		int n = 5;
      		for(int i=n; i>=1; i--)
      		{
      			for(int j=n-i; j>=1; j--)
      			{
      				System.out.print(" ");
      			}
      			for(int k=i; k>=1; k--)
      			{
      				System.out.print(k*2-1+" ");
      			}
      			System.out.println();
      		}
      	}
      }
      Reply
  60. mohseen says

    August 2, 2019 at 11:00 am

    1
    1 4
    1 8 27

    Reply
    • javainterviewpoint says

      August 3, 2019 at 12:04 pm

      Your pattern

      public class Pattern
      {
          public static void main(String[] args)
          {
              for (int i = 1; i <= 5; i++)
              {
                  for(int j=1; j<=i; j++)
                  {
                      System.out.print((int)Math.pow(j, i)+" ");
                  }
                  System.out.println();
              }
          }
      }
      Reply
  61. krishna says

    August 3, 2019 at 1:09 am

    1
    2 3 2
    4 5 6 5 4
    7 8 9 0 9 8 7
    1 2 3 4 5 4 3 2 1
    6 7 8 9 0 1 0 9 8 7 6

    hello sir, anyone try this pattern send me the code.

    Reply
    • javainterviewpoint says

      August 3, 2019 at 1:14 pm

      Have added you pattern – Pattern 54

      Reply
  62. DEVIL says

    August 15, 2019 at 12:54 pm

    PLEASE HELP ME WITH THIS:-
    A B C D E D C B A
    A B C D 1 D C B A
    A B C 1 2 1 C B A
    A B 1 2 3 2 1 B A
    A 1 2 3 4 3 2 1 A
    A B 1 2 3 2 1 B A
    A B C 1 2 1 C B A
    A B C D 1 D C B A
    A B C D E D C B A

    Reply
    • javainterviewpoint says

      August 16, 2019 at 6:14 pm

      Here you go

      import java.util.Scanner;
      
      public class Pattern
      {
          public static void main(String[] args)
          {
              // Create a new Scanner object
              Scanner scanner = new Scanner(System.in);
              // Get the number of rows from the user
              System.out.println("Enter the number of rows needed to in the pattern ");
              int rows = scanner.nextInt();
              System.out.println("## Printing the pattern ##");
              int alphabet = 65;
              for (int i = 0; i <= rows; i++)
              {
                  for (int j = 0; j <= rows - i; j++)
                  {
                      System.out.print((char) (alphabet + j) + " ");
                  }
                  for (int k = 1; k <= i; k++)
                  {
                      System.out.print(k + " ");
                  }
                  for (int l = i - 1; l >= 1; l--)
                  {
                      System.out.print(l + " ");
                  }
                  for (int m = rows - i; m >= 0; m--)
                  {
                      if (m != rows)
                          System.out.print((char) (alphabet + m) + " ");
                  }
                  System.out.println();
              }
      
              for (int i = rows - 1; i >= 0; i--)
              {
                  for (int j = 0; j <= rows - i; j++)
                  {
                      System.out.print((char) (alphabet + j)+" ");
                  }
                  
                  for (int k = 1; k <= i; k++)
                  {
                      System.out.print(k + " ");
                  }
                  for (int l = i - 1; l >= 1; l--)
                  {
                      System.out.print(l + " ");
                  }
                  
                  for (int l = rows - i; l >= 0; l--)
                  {
                      if (l != rows)
                          System.out.print((char) (alphabet + l)+" ");
                  }
                  System.out.println();
              }
      
          }
      }
      Reply
  63. Shreya gupta says

    August 21, 2019 at 11:07 pm

    Can anyone plz help me with this :
    9
    79
    579
    3579
    13579
    And Also with
    99999
    77777
    55555
    33333
    11111

    Reply
    • javainterviewpoint says

      August 23, 2019 at 12:22 pm

      Here you go
      Pattern1

      public class Pattern
      {
      	public static void main(String[] args)
      	{
      		int rows = 5;
      		for(int i=rows; i>=1; i--)
      		{
      			for(int j=i*2-1; j<=rows*2-1; j+=2)
      			{
      				System.out.print(j+" ");
      			}
      			System.out.println();
      		}
      	}
      }

      Pattern2

      public class Pattern
      {
      	public static void main(String[] args)
      	{
      		int rows = 5;
      		for(int i=rows; i>=1; i--)
      		{
      			for(int j= 1; j<=rows; j++)
      			{
      				System.out.print(i*2-1+" ");
      			}
      			System.out.println();
      		}
      	}
      }
      Reply
  64. Devesh Kumar says

    August 23, 2019 at 11:36 pm

    Can anyone plz help me with this :
    1
    1*2
    1*2*3
    1*2*3*4
    1*2*3*4*5

    Reply
    • javainterviewpoint says

      August 24, 2019 at 9:27 pm

      Your pattern

      public class Pattern
      {
      	public static void main(String[] args)
      	{
      		int rows = 5;
      		int temp =1;
      		for(int i=1; i<=rows; i++)
      		{
      			temp =1;
      			for(int j= 1; j<=i*2-1; j++)
      			{
      				if(j%2 == 0)
      				{
      					System.out.print("* ");
      				}
      				else
      				{
      					System.out.print(temp+" ");
      					temp++;
      				}
      			}
      			System.out.println();
      		}
      	}
      }
      Reply
  65. Devesh Kumar says

    August 23, 2019 at 11:38 pm

    And one more with:
    1
    2 3
    4 5 6
    7 8 9 1
    2 3 4 5 6

    Reply
    • javainterviewpoint says

      August 24, 2019 at 9:22 pm

      Your program

      public class Pattern
      {
      	public static void main(String[] args)
      	{
      		int rows = 5;
      		int temp =1;
      		for(int i=1; i<=rows; i++)
      		{
      			for(int j= 1; j<=i; j++)
      			{
      				if(temp <= rows * 2 -1)
      				{
      					System.out.print(temp+" ");
      					temp++;
      				}
      				else
      				{
      					temp = 1;
      					System.out.print(temp+" ");
      					temp++;
      				}
      			}
      			System.out.println();
      		}
      	}
      }
      Reply
  66. arshdeep says

    August 24, 2019 at 11:32 pm

    sir can you please solve this
    * * * * * *
    * * * *
    * *

    * *
    * * * *
    * * * * * *

    Reply
    • javainterviewpoint says

      August 26, 2019 at 11:44 pm

      I didn’t clearly get the pattern, guess this is what you are looking for Pattern 27 of Star Pattern program

      Reply
  67. Devid parker says

    September 24, 2019 at 4:14 pm

    Write a Java program to display the number rhombus structure. Go to the editor
    Input the number: 7 Expected Output :
    1
    212
    32123
    4321234
    543212345
    65432123456
    7654321234567
    65432123456
    543212345
    4321234
    32123
    212
    1
    Write a Java program to display the following character rhombus structure.
    A
    ABA
    ABCBA
    ABCDCBA
    ABCDEDCBA
    ABCDEFEDCBA
    ABCDEFGFEDCBA
    ABCDEFEDCBA
    ABCDEDCBA
    ABCDCBA
    ABCBA
    ABA
    A

    Reply
    • javainterviewpoint says

      September 26, 2019 at 3:21 pm

      Here you go
      Pattern 1

      public class Pattern
      {
      	public static void main(String[] args)
      	{
      		int rows = 7;
      		System.out.println("** Printing the pattern... **");
      		// Top Half
      		for (int i = 1; i <= rows; i++)
      		{
      			for (int j = i; j >= 1; j--)
      			{
      				System.out.print(j + " ");
      			}
      			for (int k = 2; k <= i; k++)
      			{
      				System.out.print(k + " ");
      			}
      			System.out.println();
      		}
      		
      		// Bottom Half
      		for (int i = rows - 1; i >= 1; i--)
      		{
      			for (int j = i; j >= 1; j--)
      			{
      				System.out.print(j + " ");
      			}
      			for (int k = 2; k <= i; k++)
      			{
      				System.out.print(k + " ");
      			}
      			System.out.println();
      		}
      
      	}
      }

      Pattern 2

      public class Pattern
      {
      	public static void main(String[] args)
      	{
      		int rows = 7;
      		int ascii = 65;
      		System.out.println("** Printing the pattern... **");
      		// Top Half
      		for (int i = 1; i <= rows; i++)
      		{
      			for (int j = 1; j <= i; j++)
      			{
      				System.out.print((char)(j + ascii - 1) + " ");
      			}
      			for (int k = i - 1; k >= 1; k--)
      			{
      				System.out.print((char)(k + ascii - 1) + " ");
      			}
      			System.out.println();
      		}
      		// Bottom Half
      		for (int i = rows - 1; i >= 1; i--)
      		{
      			for (int j = 1; j <= i; j++)
      			{
      				System.out.print((char)(j + ascii - 1) + " ");
      			}
      			for (int k = i - 1; k >= 1; k--)
      			{
      				System.out.print((char)(k + ascii - 1) + " ");
      			}
      			System.out.println();
      		}
      	}
      }
      Reply
  68. Shobhan Dasthakur says

    June 8, 2020 at 11:58 am

    1
    1 1
    1 2 1
    1 3 3 1
    1 4 6 4 1
    1 5 10 10 5 1

    Reply
    • javainterviewpoint says

      June 8, 2020 at 1:39 pm

      Have added you pattern – Pattern 57

      Reply
  69. Sukumar kyra says

    August 4, 2020 at 7:19 pm

    Can u please tell how to print the following program
    1
    2*3
    4*5*6
    7*8*9*10
    4*5*6
    2*3
    1

    By giving input as 4

    Reply
    • javainterviewpoint says

      August 4, 2020 at 10:05 pm

      public class Pattern {
        public static void main(String[] args) {
          int rows = 4;
          int num = 1;
      
          for (int i = 1; i <= rows; i++) {
            int val = i * 2 - 1;
            for (int j = 1; j <= val; j++) {
              if (j % 2 == 0) {
                System.out.print("* ");
              } else {
                System.out.print(num + " ");
                num++;
              }
            }
            System.out.println();
          }
      
          num = num - rows - 1;
          for (int i = rows - 1; i >= 1; i--) {
            int reverse = num - i;
            for (int j = i * 2 - 1; j >= 1; j--) {
              if (j % 2 == 0) {
                System.out.print("* ");
              } else {
                System.out.print(reverse + 1 + " ");
                reverse++;
                num--;
              }
            }
            System.out.println();
          }
        }
      }
      Reply
  70. R karthik says

    August 16, 2020 at 10:19 am

    1
    1 2
    2 2 3
    3 3 3 4
    4 4 4 4 5
    5 5 5 5 5 6
    Sir how to print above pattern

    Reply
    • javainterviewpoint says

      August 16, 2020 at 5:51 pm

      Here you go

      public class Test {
        public static void main(String[] args) {
          for (int i = 1; i <= 6; i++) {
            for (int j = 1; j <= i; j++) {
              if (i == 1) System.out.print(i);
              else if (j == i && j != 1) System.out.print(i);
              else System.out.print(i - 1);
            }
            System.out.println();
          }
        }
      }
      Reply
  71. Ishwar Ram says

    August 17, 2020 at 10:58 am

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

    How to create this type pattern Sir?please help me sir

    Reply
    • javainterviewpoint says

      August 17, 2020 at 10:43 pm

      Here you go

      public class Test {
      	public static void main(String[] args) {
      		for (int i = 1; i <= 5; i++) {
      			for (int j = 1; j <= i; j++) {
      				System.out.print(j);
      			}
      			for (int k = 1; k <= i; k++) {
      				System.out.print("*");
      			}
      			System.out.println();
      		}
      	}
      }
      Reply
  72. Krishna says

    August 17, 2020 at 11:04 am

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

    Please help me sir also this program

    Reply
    • javainterviewpoint says

      August 17, 2020 at 10:49 pm

      Here you go

      public class Test {
      	public static void main(String[] args) {
      		for (int i = 1; i <= 6; i++) {
      			int temp = i;
      			for (int j = 1; j <= i; j++) {
      				if (i % 2 == 0) {
      					System.out.print(temp);
      					temp--;
      				} else System.out.print(j);
      			}
      			System.out.println();
      		}
      	}
      }
      Reply
  73. snow says

    November 5, 2020 at 10:08 pm

    1 # #
    $ 1 #
    $ $ 1

    please solve this

    Reply
    • javainterviewpoint says

      November 8, 2020 at 4:22 pm

      Here you go

      public class Test
      {
         public static void main(String[] args)
         {
            for (int i = 1; i <= 3; i++)
            {
               for (int j = 1; j <= 3; j++)
               {
                  if (i == j)
                     System.out.print("1 ");
                  if (i < j)
                     System.out.print("# ");
                  if (i > j)
                     System.out.print("& ");
               }
               System.out.println();
            }
      
         }
      }
      Reply
  74. Rohit Raj says

    December 5, 2020 at 9:01 am

    Plzzzz print this pattern:

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

    Reply
    • javainterviewpoint says

      December 6, 2020 at 7:01 pm

      Here you go

      public class Pattern
      {
         public static void main(String[] args)
         {
            System.out.println("** Printing the pattern... **");
            int temp = 5;
            for (int i = 5; i >= 1; i--)
            {
               for (int j = 1; j <= 5; j++)
               {
                  if (i % 2 == 0)
                  {
                     System.out.print(temp - j + 1 + " ");
                  } else
                  {
                     System.out.print(j + " ");
                  }
      
               }
               System.out.println();
            }
         }
      }
      Reply
  75. Subham ghosh says

    December 6, 2020 at 8:31 pm

    can you please tell the code of this prattern
    1 1 1 1 1
    3 3 3 3
    5 5 5
    7 7
    9

    Reply
    • javainterviewpoint says

      December 6, 2020 at 8:36 pm

      Here you go

      public class Pattern
      {
         public static void main(String[] args)
         {
            for (int i = 1; i <= 5; i++)
            {
               for (int j = 5; j >= i; j--)
               {
                  System.out.print((i * 2) - 1 + " ");
               }
               System.out.println();
            }
         }
      }
      Reply
  76. Rohit says

    December 9, 2020 at 12:00 pm

    Plzzzz…. print this pattern

    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

    Reply
    • javainterviewpoint says

      December 10, 2020 at 12:37 pm

      Here you go

      public class Pattern {
      	public static void main(String[] args) {
      		int rows = 5;
      		for (int i = rows; i >= 1; i--) {
      			for (int j = 1; j <= i; j++) {
      				System.out.print(j + " ");
      			}
      			System.out.println();
      		}
      		for (int i = 2; i <= rows; i++) {
      			for (int j = 1; j <= i; j++) {
      				System.out.print(j + " ");
      			}
      			System.out.println();
      		}
      	}
      }
      Reply
      • Rohit says

        December 10, 2020 at 8:36 pm

        Thanks

        Reply
  77. Rohit says

    December 12, 2020 at 7:13 pm

    Plzzz…. print this pattern

    1
    3 3
    5 5 5
    7 7 7 7
    .
    .
    .
    .
    n rows

    Reply
    • javainterviewpoint says

      December 14, 2020 at 12:50 pm

      Here you go

      import java.util.Scanner;
      
      public class Pattern {
      	public static void main(String[] args) {
      		// Create a new Scanner object
      		Scanner scanner = new Scanner(System.in);
      		// Get the number of rows from the user
      		System.out.println("Enter the number of rows to print the pattern ");
      		int rows = scanner.nextInt();
      		for (int i = 1; i <= rows; i++) {
      			for (int j = 1; j <= i; j++) {
      				System.out.print((i * 2) - 1 + " ");
      			}
      			System.out.println();
      		}
      	}
      }
      Reply
  78. Rohit says

    December 12, 2020 at 7:15 pm

    Plzzz….. Print this pattern

    1
    2 3
    4 5 6
    7 8 9 10
    .
    .
    .
    .
    n rows

    Reply
    • javainterviewpoint says

      December 14, 2020 at 12:51 pm

      Here you go

      import java.util.Scanner;
      
      public class Pattern {
      	public static void main(String[] args) {
      		// Create a new Scanner object
      		Scanner scanner = new Scanner(System.in);
      		// Get the number of rows from the user
      		System.out.println("Enter the number of rows to print the pattern ");
      		int temp = 1;
      		int rows = scanner.nextInt();
      		for (int i = 1; i <= rows; i++) {
      			for (int j = 1; j <= i; j++) {
      				System.out.print(temp + " ");
      				temp++;
      			}
      			System.out.println();
      		}
      	}
      }
      Reply
  79. Rohit says

    December 12, 2020 at 7:17 pm

    Plzzz….. Print this pattern

    1
    0 0
    1 1 1
    0 0 0 0
    1 1 1 1 1

    Reply
    • javainterviewpoint says

      December 14, 2020 at 12:53 pm

      Here you go

      import java.util.Scanner;
      
      public class Pattern {
      	public static void main(String[] args) {
      		// Create a new Scanner object
      		Scanner scanner = new Scanner(System.in);
      		// Get the number of rows from the user
      		System.out.println("Enter the number of rows to print the pattern ");
      		int rows = scanner.nextInt();
      		for (int i = 1; i <= rows; i++) {
      			for (int j = 1; j <= i; j++) {
      				System.out.print( i%2 + " ");
      			}
      			System.out.println();
      		}
      	}
      }
      Reply
  80. Rohit says

    December 12, 2020 at 7:18 pm

    Plzzz…… Print this pattern

    1
    1 0
    1 0 1
    1 0 1 0
    1 0 1 0 1
    .
    .
    .
    .
    n rows

    Reply
    • javainterviewpoint says

      December 14, 2020 at 12:54 pm

      Here you go

      import java.util.Scanner;
      
      public class Pattern {
      	public static void main(String[] args) {
      		// Create a new Scanner object
      		Scanner scanner = new Scanner(System.in);
      		// Get the number of rows from the user
      		System.out.println("Enter the number of rows to print the pattern ");
      		int rows = scanner.nextInt();
      		for (int i = 1; i <= rows; i++) {
      			for (int j = 1; j <= i; j++) {
      				System.out.print( j%2 + " ");
      			}
      			System.out.println();
      		}
      	}
      }
      Reply
  81. parikshit naskar says

    January 1, 2022 at 10:06 am

    pls solve the problem

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

    Reply
  82. parikshit naskar says

    January 14, 2022 at 1:31 pm

    Pls solve the problem of the above . It is very urgent to me.

    Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Java Basics

  • JVM Architecture
  • Object in Java
  • Class in Java
  • How to Set Classpath for Java in Windows
  • Components of JDK
  • Decompiling a class file
  • Use of Class.forName in java
  • Use Class.forName in SQL JDBC

Oops Concepts

  • Inheritance in Java
  • Types of Inheritance in Java
  • Single Inheritance in Java
  • Multiple Inheritance in Java
  • Multilevel Inheritance in Java
  • Hierarchical Inheritance in Java
  • Hybrid Inheritance in Java
  • Polymorphism in Java – Method Overloading and Overriding
  • Types of Polymorphism in java
  • Method Overriding in Java
  • Can we Overload static methods in Java
  • Can we Override static methods in Java
  • Java Constructor Overloading
  • Java Method Overloading Example
  • Encapsulation in Java with Example
  • Constructor in Java
  • Constructor in an Interface?
  • Parameterized Constructor in Java
  • Constructor Chaining with example
  • What is the use of a Private Constructors in Java
  • Interface in Java
  • What is Marker Interface
  • Abstract Class in Java

Java Keywords

  • Java this keyword
  • Java super keyword
  • Final Keyword in Java
  • static Keyword in Java
  • Static Import
  • Transient Keyword

Miscellaneous

  • newInstance() method
  • How does Hashmap works internally in Java
  • Java Ternary operator
  • How System.out.println() really work?
  • Autoboxing and Unboxing Examples
  • Serialization and Deserialization in Java with Example
  • Generate SerialVersionUID in Java
  • How to make a class Immutable in Java
  • Differences betwen HashMap and Hashtable
  • Difference between Enumeration and Iterator ?
  • Difference between fail-fast and fail-safe Iterator
  • Difference Between Interface and Abstract Class in Java
  • Difference between equals() and ==
  • Sort Objects in a ArrayList using Java Comparable Interface
  • Sort Objects in a ArrayList using Java Comparator

Follow

  • Coding Utils

Useful Links

  • Spring 4.1.x Documentation
  • Spring 3.2.x Documentation
  • Spring 2.5.x Documentation
  • Java 6 API
  • Java 7 API
  • Java 8 API
  • Java EE 5 Tutorial
  • Java EE 6 Tutorial
  • Java EE 7 Tutorial
  • Maven Repository
  • Hibernate ORM

About JavaInterviewPoint

javainterviewpoint.com is a tech blog dedicated to all Java/J2EE developers and Web Developers. We publish useful tutorials on Java, J2EE and all latest frameworks.

All examples and tutorials posted here are very well tested in our development environment.

Connect with us on Facebook | Privacy Policy | Sitemap

Copyright ©2023 · Java Interview Point - All Rights Are Reserved ·