Created
March 10, 2022 08:47
-
-
Save thomasw-mitutoyo-ctl/79ece0ba0264cb39c437984a0b63202b to your computer and use it in GitHub Desktop.
Zahlen mit Ziffer 3 von vorne
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
import "dart:math" as math; | |
void main() { | |
var anzahlZahlenMitDrei = 0; | |
for (var i = 100; i <= 999; i++) { | |
for (int stelle = 6; stelle > 0; stelle--) { | |
var wertigkeit = math.pow(10, stelle).toInt(); // 10^stelle | |
var hintenAbgeschnitten = i ~/ (wertigkeit ~/ 10); | |
var vorneAbgeschnitten = hintenAbgeschnitten % 10; | |
if (vorneAbgeschnitten == 3) { | |
anzahlZahlenMitDrei++; | |
break; // for-Schleife beenden | |
} | |
} | |
} | |
print("Anzahl Zahlen mit 3: ${anzahlZahlenMitDrei}"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment