Advertisement
narimetisaigopi

odd even insert

Apr 4th, 2021
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.46 KB | None | 0 0
  1. void main() {
  2. myFunc("99946");
  3. }
  4.  
  5. void myFunc(String data) {
  6. bool isOdd = false;
  7. String result = "";
  8. for (var x in data.split("")) {
  9. if (int.parse(x) % 2 == 0 && !isOdd) {
  10. result += "*" + x;
  11. } else if (int.parse(x) % 2 != 0 && isOdd) {
  12. result += "-" + x;
  13. } else {
  14. result += x;
  15. }
  16.  
  17. if (int.parse(x) % 2 == 0) {
  18. isOdd = false;
  19. } else {
  20. isOdd = true;
  21. }
  22. }
  23.  
  24. print("result $result");
  25. }
  26.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement