Created
May 29, 2014 22:42
-
-
Save HabaCo/707312ec3d6485f75643 to your computer and use it in GitHub Desktop.
Print星星
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
| public class Test03 { | |
| public static void main(String[] args) { | |
| int length = 13; // 行數可任意變更,配合 work4 建議奇數為主 | |
| System.out.println("Work1.."); | |
| for (int i = 0; i < length; i++) { | |
| for (int j = 0; j < length; j++) | |
| System.out.print("★"); | |
| System.out.println(); | |
| } | |
| System.out.println("Work2.."); | |
| for (int i = 0; i < length; i++) { | |
| for (int j = 0; j <= i; j++) | |
| System.out.print("★"); | |
| System.out.println(); | |
| } | |
| System.out.println("Work3.."); | |
| for (int i = 0; i < length; i++) { | |
| for (int j = length; j > i; j--) | |
| System.out.print("★"); | |
| System.out.println(); | |
| } | |
| System.out.println("Work4.."); // 令 n = 行數, L = 長 | |
| for (int i = 0; i < length / 2 + 1; i++) { | |
| for (int j = length / 2; j > i; j--) | |
| // 白色星星隨著行數(n)遞減為(L/2-n)個 | |
| System.out.print("☆"); | |
| for (int j = 0; j < 2 * (i + 1) - 1; j++) | |
| // 黑色星星隨著行數(n)遞增為(2*n-1) | |
| System.out.print("★"); | |
| for (int j = length / 2; j > i; j--) | |
| // 白色星星隨著行數(n)遞減為(L/2-n)個 | |
| System.out.print("☆"); | |
| System.out.println(); | |
| } | |
| System.out.println("Work5..continue Work4"); // 接續 Work4 使之成為菱形 | |
| for (int i = length / 2 + 1; i < length; i++) { | |
| for (int j = length / 2; j < i; j++) | |
| // 白色星星隨著行數(n)遞增為(n-L/2)個 | |
| System.out.print("☆"); | |
| for (int j = 0; j < 2 * (length - i) - 1; j++) | |
| // 黑色星星隨著行數(n)遞減為(2*(L-n)-1) | |
| System.out.print("★"); | |
| for (int j = length / 2; j < i; j++) | |
| // 白色星星隨著行數(n)遞增為(n-L/2)個 | |
| System.out.print("☆"); | |
| System.out.println(); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment