diamond star in java

Solutions on MaxInterview for diamond star in java by the best coders in the world

showing results for - "diamond star in java"
Matteo
30 Jun 2018
1import java.util.Scanner;
2public class Diamond 
3{
4 
5public static void main(String[] args)
6{
7 
8Scanner sc=new Scanner(System.in);
9System.out.println("Enter N : ");
10int n=sc.nextInt(); 
11System.out.print("Enter Symbol : ");
12 
13char c = sc.next().charAt(0);
14 
15for(int i=1;i<=n;i++)
16{
17for(int j=1;j<=n-i;j++)
18 
19{
20System.out.print(" ");
21}
22 
23for(int j=1;j<=i*2-1;j++)
24 
25{
26System.out.print(c);
27}
28System.out.println();
29 
30} 
31for(int i=n-1;i>0;i--)
32{
33for(int j=1;j<=n-i;j++)
34 
35{
36System.out.print(" ");
37}
38for(int j=1;j<=i*2-1;j++)
39 
40{
41System.out.print(c);
42}
43System.out.println();
44}
45 
46}
47}
48