Java Program to Create a Diamond
Create a Diamond Shape using this Java Code
Java
import java.util.Scanner;
public class Diamond {
public static void main(String[] args) {
int n, i, p,
space = 1;
Scanner s=new Scanner(System.in);
System.out.println("Enter number of rows: ");
n=s.nextInt();
space = n - 1;
for (p = 1; p<=n; p++) {
for (i = 1; i<=space; i++)
System.out.print(" ");
space--;
for (i = 1; i<= 2*p-1; i++)
System.out.print("*");
System.out.print("\n");}
System.out.print("\n");}
space = 1;
for (p = 1; p<= n - 1; p++) {
for (i = 1; i<= space; i++)
System.out.print(" ");
space++;
for (i = 1 ; i<= 2*(n-p)-1; i++)
System.out.print("*");
System.out.println(""); } } }
System.out.println(""); } } }
Comments
Post a Comment