language: Java (sun-jdk-1.7.0_10)
date: 153 days 0 hours ago
link:
visibility: public
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
class Main
{
    public static void main(String[] args)
    {
        stars();
    }
    
    static void stars()
    {
        final int MAX_WIDTH = 7;
        
        for (int i = 0; i < 7; ++i)
        {
            int width;
            
            if (i < 3) width = MAX_WIDTH - i * 2;
            else if (i > 3) width = (i - 3) * 2 + 1;
            else width = 1;
            
            // Before spaces
            
            for (int j = 0; j < (MAX_WIDTH - width) / 2; ++j)
            {
                System.out.print(" ");
            }
            
            // Stars
            
            for (int j = 0; j < width; ++j)
            {
                System.out.print("*");
            }
            
            // After spaces
            
            for (int j = 0; j < (MAX_WIDTH - width) / 2; ++j)
            {
                System.out.print(" ");
            }
            
            System.out.println();
        }
    }
}