Search code examples
arithmetic-expressions

How to find missing value from equation using java?


User made some calculations using program..and printed it on paper.. But mouse cut some part from the paper.

Now we have to create the program to find missing values.

Example:

54 + 27 = HOLE
3241 + 4HOLE45=7281

We have to find the missing value at HOLE. If we pass multiple eqution at a time.


Solution

  • If (like in your example) the equations are separated by line breaks (or any other character will work) simply separate the equations maybe into custom objects then you can split each equations to numbers by splitting at every arithmetic symbols.

    What I am suggesting is to phrase each line as an equation and find the missing bit by comparing both sides of the equal sign. You can find any one missing number each from any equation like this.

    I have not provided any code example because you have not provided any code that you have currently tried out and also no specific language is specified. If you follow up with those I am ready to give a code sample.