Skip to content

Instantly share code, notes, and snippets.

@nhojpatrick
Last active April 23, 2017 15:11
Show Gist options
  • Save nhojpatrick/7a39f67472723a3dce74d41b3e27551d to your computer and use it in GitHub Desktop.
Save nhojpatrick/7a39f67472723a3dce74d41b3e27551d to your computer and use it in GitHub Desktop.
1 Loop & 1 StringBuilder
public class Pattern {
public static void main(final String[] args) {
final StringBuilder sb = new StringBuilder();
for (int i = 1; i <= 7; i++) {
System.out.println(String.format("%s %s %s", sb.toString(), i, sb.reverse()));
sb.reverse().append(" " + i);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment