how to replace characters in a string with integers?
Say I have the the string: " aab + bab = b " and I want to
replace all the a characters with the integer 0,
replace all the b characters with the integer 1
so it will become:
001 + 101 = 1
what would be the easiest way to do this?
so far I parced the equation into three parts:
System.out.println("Enter an Equation of variables");
_inString = _in.nextLine();
//find the three different parts of the equation
String _noSpaces = _inString.replaceAll("\\s+","");
String delims = "[+,=]";
String[] _tokens = _noSpaces.split(delims);
No comments:
Post a Comment