SHOW:
|
|
- or go back to the newest paste.
| 1 | import java.util.Scanner; | |
| 2 | public class GeorgeHany {
| |
| 3 | public static void main (String [] args){
| |
| 4 | Scanner sc = new Scanner (System.in); | |
| 5 | System.out.print("Enter a positive odd number: ");
| |
| 6 | int n = sc.nextInt(); | |
| 7 | if (n == 1){
| |
| 8 | System.out.println("*");
| |
| 9 | } | |
| 10 | else {
| |
| 11 | int c = n/2 + 1; | |
| 12 | for (int i=1; i<c; i++) | |
| 13 | System.out.print(" ");
| |
| 14 | System.out.println("*");
| |
| 15 | int spaces1 = c - 2; | |
| 16 | int spaces2 = 0; | |
| 17 | for (int i=2; i<c; i++){
| |
| 18 | for (int j=1; j<=spaces1; j++) | |
| 19 | System.out.print(" ");
| |
| 20 | System.out.print("*");
| |
| 21 | for (int j=1; j<=spaces2; j++) | |
| 22 | System.out.print(" ");
| |
| 23 | System.out.print("*");
| |
| 24 | for (int j=1; j<=spaces2; j++) | |
| 25 | System.out.print(" ");
| |
| 26 | System.out.println("*");
| |
| 27 | spaces1--; | |
| 28 | spaces2++; | |
| 29 | } | |
| 30 | for (int i=1; i<=n; i++) | |
| 31 | System.out.print("*");
| |
| 32 | System.out.println("");
| |
| 33 | spaces1 = 1; | |
| 34 | spaces2 = c - 3; | |
| 35 | for (int i=2; i<c; i++){
| |
| 36 | for (int j=1; j<=spaces1; j++) | |
| 37 | System.out.print(" ");
| |
| 38 | System.out.print("*");
| |
| 39 | for (int j=1; j<=spaces2; j++) | |
| 40 | System.out.print(" ");
| |
| 41 | System.out.print("*");
| |
| 42 | for (int j=1; j<=spaces2; j++) | |
| 43 | System.out.print(" ");
| |
| 44 | System.out.println("*");
| |
| 45 | spaces1++; | |
| 46 | spaces2--; | |
| 47 | } | |
| 48 | for (int i=1; i<c; i++) | |
| 49 | System.out.print(" ");
| |
| 50 | System.out.print("*");
| |
| 51 | } | |
| 52 | } | |
| 53 | ||
| 54 | } |