Created
May 21, 2017 16:33
-
-
Save sat0b/b6495c662a1c2c3fd59e9690fe4837c4 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| import java.util.Scanner; | |
| class Hishigata { | |
| public static void main(String[] args) { | |
| int n = 0; | |
| try { | |
| n = Integer.parseInt(args[0]); | |
| } catch (NumberFormatException e) { | |
| e.printStackTrace(); | |
| System.exit(1); | |
| } | |
| if (n < 2) { | |
| System.out.println("Input Error : n >= 2 expected, but " + n); | |
| System.exit(1); | |
| } | |
| showDiamond(n); | |
| } | |
| private static void showDiamond(int n) { | |
| int center = n - 1; | |
| int cnt; | |
| for (int i = 0; i < 2 * n - 1; i++) { | |
| cnt = 0; | |
| for (int j = 0; j < n; j++) { | |
| if (Math.abs(i - center) > j) | |
| System.out.print(" "); | |
| else { | |
| System.out.print("*"); | |
| cnt++; | |
| } | |
| } | |
| for (int j = 0; j < cnt - 1; j++) { | |
| System.out.print("*"); | |
| } | |
| System.out.println(); | |
| } | |
| } | |
| } |
This file contains hidden or 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
| === input 2 === | |
| * | |
| *** | |
| * | |
| === input 3 === | |
| * | |
| *** | |
| ***** | |
| *** | |
| * | |
| === input 4 === | |
| * | |
| *** | |
| ***** | |
| ******* | |
| ***** | |
| *** | |
| * | |
| === input 5 === | |
| * | |
| *** | |
| ***** | |
| ******* | |
| ********* | |
| ******* | |
| ***** | |
| *** | |
| * | |
| === input 10 === | |
| * | |
| *** | |
| ***** | |
| ******* | |
| ********* | |
| *********** | |
| ************* | |
| *************** | |
| ***************** | |
| ******************* | |
| ***************** | |
| *************** | |
| ************* | |
| *********** | |
| ********* | |
| ******* | |
| ***** | |
| *** | |
| * |
This file contains hidden or 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
| #!/bin/bash | |
| set -eu | |
| javac Hishigata.java | |
| echo "=== input 2 ===" | |
| java Hishigata 2 | |
| echo "=== input 3 ===" | |
| java Hishigata 3 | |
| echo "=== input 4 ===" | |
| java Hishigata 4 | |
| echo "=== input 5 ===" | |
| java Hishigata 5 | |
| echo "=== input 10 ===" | |
| java Hishigata 10 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment