private static String muliplier ( String formula , int factor ) { String finalformula = "" ; String recentElementSymbol = "" ; String recentElementCountString = "0" ; for ( int f = 0 ; f < formula . length ( ) ; f ++ ) { char thisChar = formula . charAt ( f ) ; if ( f < formula . length ( ) ) { if ( thisChar >= ' ' && thisChar <= ' ' ) { recentElementSymbol = String . valueOf ( thisChar ) ; recentElementCountString = "0" ; } if ( thisChar >= ' ' && thisChar <= ' ' ) { recentElementSymbol += thisChar ; } if ( thisChar >= ' ' && thisChar <= ' ' ) { recentElementCountString += thisChar ; } } if ( f == formula . length ( ) - 1 || ( formula . charAt ( f + 1 ) >= ' ' && formula . charAt ( f + 1 ) <= ' ' ) ) { Integer recentElementCount = Integer . valueOf ( recentElementCountString ) ; if ( recentElementCount == 0 ) finalformula += recentElementSymbol + factor ; else finalformula += recentElementSymbol + recentElementCount * factor ; } } return finalformula ; }
This method multiply all the element over a value .