(Coderbyte) Dash Insert II - Solução
Have the function DashInsertII( str ) insert dashes ('-') between each two odd numbers and insert asterisks ('*') between each two even numbers in str . For example: if str is 4546793 the output should be 454*67-9-3 . Don't count zero as an odd or even number. import java.util.*; import java.io.*; class Function { String DashInsertII(String num) { int anterior = Integer.parseInt(String.valueOf(num.charAt(0))); String resultado = String.valueOf(num.charAt(0)); for (int i = 1; i < num.length(); i++) { int atual = Integer.parseInt(String.valueOf(num.charAt(i))); if (anterior%2 == 0 && atual%2 == 0 && anterior != 0 && atual != 0) { resultado += "*"; } else if (anterior%2 == 1 && atual%2 == 1) { ...