| 144 | } |
| 145 | |
| 146 | public static void diamond(int n) { |
| 147 | //1st half |
| 148 | for(int i=1; i<=n; i++) { |
| 149 | //spaces |
| 150 | for(int j=1; j<=n-i; j++) { |
| 151 | System.out.print(" "); |
| 152 | } |
| 153 | |
| 154 | //stars |
| 155 | for(int j=1; j<=(2*i)-1; j++) { |
| 156 | System.out.print("*"); |
| 157 | } |
| 158 | System.out.println(); |
| 159 | } |
| 160 | |
| 161 | //2nd half |
| 162 | for(int i=n; i>=0; i--) { |
| 163 | //spaces |
| 164 | for(int j=1; j<=n-i; j++) { |
| 165 | System.out.print(" "); |
| 166 | } |
| 167 | |
| 168 | //stars |
| 169 | for(int j=1; j<=(2*i)-1; j++) { |
| 170 | System.out.print("*"); |
| 171 | } |
| 172 | System.out.println(); |
| 173 | } |
| 174 | } |
| 175 | |
| 176 | public static void number_pyramid(int n) { |
| 177 | for(int i=1; i<=n; i++) { |