Printing Diamond Pattern in Java with Source Code

Printing Diamond Pattern in Java; We’ve written the diamond asterisk/star pattern print/draw program in four different ways, each with a sample example and output.

We put a download button at the end of the program so that you may download the source code for free in this project.

Sample Code:

//Java Printing Diamond Pattern in Java : Sample Code    


package printingdiamondpattern;

import java.util.Scanner;

public class PrintingDiamondPattern {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.println("Enter Number : ");
        int n = sc.nextInt();
        System.out.print("Enter Symbol : ");

        char c = sc.next().charAt(0);

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

            for (int j = 1; j <= i * 2 - 1; j++) {
                System.out.print(c);
            }
            System.out.println();

        }
        for (int i = n - 1; i > 0; i--) {
            for (int j = 1; j <= n - i; j++) {
                System.out.print(" ");
            }
            for (int j = 1; j <= i * 2 - 1; j++) {
                System.out.print(c);
            }
            System.out.println();
        }

    }
}

Output:

//Java Printing Diamond Pattern in Java: Sample Code Output

Enter Number : 
7
Enter Symbol : 0
      0
     000
    00000
   0000000
  000000000
 00000000000
0000000000000
 00000000000
  000000000
   0000000
    00000
     000
      0

What is the importance of Printing Diamonds in Java?

Java is an object-oriented, cross-platform, sophisticated, and reliable programming language with excellent memory management and security features. It also has a multithreading capability that allows you to build code that performs multiple functions at the same time.

There are also 11,611 monthly advertised jobs in the United States. Java is widely used. Android apps, server apps, financial apps, Big Data technology, and much more are all powered by it. It’s a talent that will benefit programmers in the job market for many years.

so it is best for beginner to learn this simple problem project.

About the Project

This project is build using Java alone the following Java project covers all of the required and vital elements that can be used for college projects by first-year, second-year, and final-year IT students.

Project Details and Technology

Project Name:Printing Diamond Pattern in Java with Source Code
AbstractThe Printing Diamond Pattern in Java is a functional project which beginners can learn in this simple program that can enhance their programming skills.
Language/s Used:Java
Java version (Recommended):8
Database:N/A
Type:Desktop Application
Developer:sourcecodehero
Updates:0

To start executing a Printing Diamond Pattern in Java, make sure that you have  NetBeans IDE or any platform of code editor installed on your computer.

How to print diamond pattern in Java: Follow the steps below

Time needed: 3 minutes

How to print diamond pattern in Java: Follow the steps below

  • Step 1: Download Source Code

    To get started, find the downloaded source code file below and click to start downloading it.

    Printing Diamond Pattern in Java

  • Step 2: Extract File

    Navigate to the file’s location when you’ve finished downloading it and right-click it to extract it.

    Printing Diamond Pattern in Java extract

  • Step 3: Run the project

    Next, open NetBeans IDE click open project, and choose your download.

    Printing Diamond Pattern in Java open projects

  • Step 4: Run the project.

    Next, right-click the project folder and click run.

Download the Source Code below

Summary

For those Web developers interested in learning more about web apps, this system is a fully functional project.

Related Article

Inquiries

If you have any questions or comments on the project, please leave a comment below.

Leave a Comment