Ok so for my assignment, I have to have two String inputs.

For example, "1.021" and "2.51"

And I need to calculate the difference between these strings (biggest number minus smaller). I can only use the data types: short, char, boolen and String. I cannot use int or double. I cannot assume that both strings have similar length or same decimal type.

Finding the biggest number is easy. And my initial idea was to convert the numbers before the decimal to short and then subtracting, then doing the same for numbers after the decimal. However I don't think that it is the proper approach to tackling it.

Given examples, "1.021" and "2.51"

We know, 2 - 1 = 1
and 0.51 - 0.21 = 0.3

BUT, 2.51 - 1.021 = 1.489

So how does one algorithmically solve this? Thanks.

1 answer

I just realized that my example provided is not clear and wrong.

How about "51.283" and "1.982"

We know 51 - 1 = 50
and 0.982 - 0.283 = 0.699

BUT, 51.283 - 1.982 = 49.301

Thank you
Similar Questions
    1. answers icon 1 answer
  1. If i have a string with a word 'today' in it.If a user inputs a char (lets say b). how do I right the array to make it see if
    1. answers icon 0 answers
  2. What is a collision in a hash function?(2 points)Responses There are few outputs, but a lot of inputs. There are few outputs,
    1. answers icon 1 answer
  3. What is a collision in a hash function?(2 points)Responses There are few inputs, but a lot of outputs. There are few inputs, but
    1. answers icon 1 answer
more similar questions