Skip to content

Instantly share code, notes, and snippets.

@gigamonkey
Created October 19, 2022 15:37
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 gigamonkey/2d81a8bba6f59d6113640a1a73b5635c to your computer and use it in GitHub Desktop.
Save gigamonkey/2d81a8bba6f59d6113640a1a73b5635c to your computer and use it in GitHub Desktop.
Ms. O'Keefe's loop challenge
/*
Write a program to generate this output:
#
$#
*$#
$*$#
*$*$#
$*$*$#
*$*$*$#
$*$*$*$#
*$*$*$*$#
$*$*$*$*$#
*/
class Main {
public static void main(String[] args) {
String s = "#";
char c = '$';
for (int i = 0; i < 10; i++) {
System.out.println(s);
s = c + s;
for (int j = 0; j < 6; j++) {
c += ((i & 1) - 0.5) * -2;
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment