Created
December 13, 2021 17:38
-
-
Save nderwin/354726f3337fac379ebf330899a5bcc1 to your computer and use it in GitHub Desktop.
Make an ASCII Christmas Tree with a jshell script
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
import java.nio.*; | |
String num = Files.readString(Path.of("merry-christmas.txt")); | |
int x = 25; | |
try { x = Integer.parseInt(num.trim()); } catch (NumberFormatException ex) {} | |
StringBuilder sb = new StringBuilder(""); | |
for (int i = 1; i <= x; i++) { sb.append(" ".repeat(x-i)).append("*".repeat(i+(i-1))).append("\n"); } | |
Files.writeString(Path.of("happy-holidays.txt"), sb.toString()); | |
/exit |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment