Skip to content

Instantly share code, notes, and snippets.

@nderwin
Created December 13, 2021 17:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nderwin/354726f3337fac379ebf330899a5bcc1 to your computer and use it in GitHub Desktop.
Save nderwin/354726f3337fac379ebf330899a5bcc1 to your computer and use it in GitHub Desktop.
Make an ASCII Christmas Tree with a jshell script
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