Created
October 19, 2022 15:37
-
-
Save gigamonkey/2d81a8bba6f59d6113640a1a73b5635c to your computer and use it in GitHub Desktop.
Ms. O'Keefe's loop challenge
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
/* | |
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