-
-
Save mariiaKolokolova/188504102f816153d5ab304ad19d1e24 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package maricka.kolokolova; | |
import java.util.Scanner; | |
public class Main { | |
public static void main(String[] args) { | |
// TODO Auto-generated method stub | |
Scanner sc = new Scanner(System.in); | |
System.out.println("Input hourglass width:"); | |
int w; | |
int ch; | |
w = sc.nextInt(); | |
ch = w % 2; | |
if (ch != 0) { | |
int midl; | |
midl = w / 2 + 1; | |
for (int i = 1; i <= w; i++) { | |
for (int j = 1; j <= w; j++) { | |
if (i <= midl) { | |
if (j <= i - 1 || j > w - i + 1) { | |
System.out.print(" "); | |
} else { | |
System.out.print("*"); | |
} | |
} else { | |
if (j < w - i + 1 || j > i) { | |
System.out.print(" "); | |
} else { | |
System.out.print("*"); | |
} | |
} | |
} | |
System.out.println(""); | |
} | |
} else { | |
System.out.println("Your number is not correct. Please try one more time."); | |
} | |
sc.close(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment