Skip to content

Instantly share code, notes, and snippets.

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 thomasw-mitutoyo-ctl/e7cf8b4b3136d8e34531d672d342a65d to your computer and use it in GitHub Desktop.
Save thomasw-mitutoyo-ctl/e7cf8b4b3136d8e34531d672d342a65d to your computer and use it in GitHub Desktop.
Zahlen, die die Ziffer 3 enthalten, gelöst mit Substring
void main() {
var anzahlZahlenMitDrei = 0;
for (var i = 100; i <= 999; i++) {
var text = i.toString();
// Nachteil: muss für jede weitere Stelle zusätzlich programmiert werden, z.B. Tausender
var hunderter = text.substring(0,1);
var zehner = text.substring(1,2);
var einer = text.substring(2,3);
if (hunderter == "3" || zehner == "3" || einer == "3") {
anzahlZahlenMitDrei++;
}
}
print("Anzahl Zahlen mit 3: ${anzahlZahlenMitDrei}");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment