Java Program to Create a Diamond



Create a Diamond Shape using this Java Code



CyberLink


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");}                   
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(""); } } }


Click Here to Run this Code










Comments

Popular posts from this blog

Crypto Mining

Multi-tap Keypad Text Entry