If present value is less than next value , subtract present from next value and add the resultant to the sum variable .
if ( i != n - 1 && roman . get ( s . charAt ( i ) ) < roman . get ( s . charAt ( i + 1 ) ) ) { sum += roman . get ( s . charAt ( i + 1 ) ) - roman . get ( s . charAt ( i ) ) ; i ++ ; } else { sum += roman . get ( s . charAt ( i ) ) ; } } return sum ; }