Created with <3 with dartpad.dev.
Created
September 12, 2023 16:16
-
-
Save hongsw/95bcceb24b881cbd4569e904cada5135 to your computer and use it in GitHub Desktop.
FizzBuzz in Dart without IF
This file contains hidden or 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
void main() { | |
for (int i = 1; i <= 100; i++) { | |
String output = ""; | |
var fizz = ["", "Fizz"]; | |
var buzz = ["", "Buzz"]; | |
output += fizz[i % 3 == 0 ? 1 : 0]; | |
output += buzz[i % 5 == 0 ? 1 : 0]; | |
print(output.isEmpty ? i.toString() : output); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment