Traversing the String
for ( int i = 0 ; i < num . length ( ) ; i ++ ) if ( i % 2 == 0 ) sumOdd = sumOdd + ( num . charAt ( i ) - '0' ) ; else sumEven = sumEven + ( num . charAt ( i ) - '0' ) ; System . out . println ( " Sum ▁ odd ▁ = ▁ " + sumOdd ) ; System . out . println ( " Sum ▁ even ▁ = ▁ " + sumEven ) ; }