String s1 = "+1-2+3-4+5+6-7";
String s2 = "1-2+3-4+5+6-7";
I want to find the value of sum of each of those string in integer ? there can be only addition or subtraction
You will have to write some code to extract the numbers,the operators between the numbers and then do the arithmetic represented by the operators.
The String class has many methods that should help you.
You just have to split your string into character by character using charAt() or indexOf() method.
Then do required arithmetic operation based on the character you got.
like either + or - or / ans so on..
Thank you.
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.