Answers for "diamond star in java"

0

diamond star in java

import java.util.Scanner;
public class Diamond 
{
 
public static void main(String[] args)
{
 
Scanner sc=new Scanner(System.in);
System.out.println("Enter N : ");
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();
}
 
}
}
Posted by: Guest on December-30-2020

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language