0% found this document useful (0 votes)
3 views

Java

This Java program creates a diamond pattern based on user input. It uses nested loops to print different characters in a specific arrangement to form the diamond shape. The program prompts the user for the number of levels and then displays the constructed diamond before ending.

Uploaded by

praveenajmsksp
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Java

This Java program creates a diamond pattern based on user input. It uses nested loops to print different characters in a specific arrangement to form the diamond shape. The program prompts the user for the number of levels and then displays the constructed diamond before ending.

Uploaded by

praveenajmsksp
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 1

Java

Dio

import java.util.Scanner;

public class Main


{
static void box(int M) {

for (int i = 0; i < M; i++) {


for (int k = M; k > i; k--) {
System.out.print("$");
}
for (int j = 0; j < i; j++) {
System.out.print("*");
}
for (int j = 0; j < i; j++) {
System.out.print("@");
}
for (int k = M; k > i; k--) {
System.out.print("-");
}
System.out.println("");
}

for (int i = 0; i < M; i++) {


for (int j = 0; j < i; j++) {
System.out.print("*");
}
for (int k = M; k > i; k--) {
System.out.print("$");
}
for (int k = M; k > i; k--) {
System.out.print("*");
}
for (int j = 0; j < i; j++) {
System.out.print("%");
}

System.out.println("");
}
}

public static void main(String[] args) {

System.out.println("Praveen's Project");

Scanner myObj = new Scanner(System.in);

System.out.println("Enter N:");

int N = myObj.nextInt();

System.out.println("Now creating "+ N +"-level Diamond");

box(N); // function call

System.out.println("End of Project");
}
}

You might also like