Java Programming Algorithm Help

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. 👍
  2. 👎
  3. 👁
  1. 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

    1. 👍
    2. 👎

Respond to this Question

First Name

Your Response

Similar Questions

  1. physics

    an object of mass 0.5 kg is whirled at the end of string 0.8 m long if the string make three revolution in 1.2 sec find the tension of the string

  2. Programming concepts

    Develop a menu-driven program that inputs two numbers and, at the user’s option, finds their sum, difference, product, or quotient. top-down modular approach and pseudocode to design a suitable program to solve it. I am having

  3. Physics

    A guitar string vibrates at 400 Hz and has a length of 0.8 m. Find the new frequency if a. the string is lengthened to 0.9 m. b. the string is replaced with another string, the density of which is greater by a factor of two. c.

  4. physics

    A 1.6-m-long string fixed at both ends vibrates at resonant frequencies of 792 Hz and 990 Hz, with no other resonant frequency between these values. (a) What is the fundamental frequency of this string? (b) When the tension in the

  1. Physics

    A stretched string is 1.93 m long and has a mass of 21.1 g. When the string is oscillated at 440 Hz, which is the frequency of the standard A pitch that orchestras tune to, transverse waves with a wavelength of 16.9 cm travel

  2. circuits 2

    Which of the following is true about the cut-off frequency ωB of a first-order low-pass filter? Suppose that the DC gain is 1. a.When the input is a sinusoid operating at ωB, the output is phase shifted from the input phase by

  3. science

    a framed picture of weight 15N is to be hung on a wall using a price of string . the end of the string are tied to two points ,0.60m apart on the same horizontal level ,on the back of the picture .Find the tension in the string if

  4. physics

    ssm A string trimmer is a tool for cutting grass and weeds; it utilizes a length of nylon "string" that rotates about an axis perpendicular to one end of the string. The string rotates at an angular speed of 56 rev/s, and its tip

  1. physics

    A string under a tension of 50.0 N is used to whirl a rock in a horizontal circle of radius 2.50 m at a speed of 20.4 m/s. The string is pulled in and the speed of the rock increases. When the string is 1.00 m long and the speed

  2. physics

    Transverse waves with a speed of 50.0 m/s are to be produced on a stretched string. A 5.00m length of string with a total of 60 grams is used. a) what is the required tension in the string? b) calculate the wave speed in the

  3. physics

    The mass of a string is 2.5 × 10-3 kg, and it is stretched so that the tension in it is 250 N. A transverse wave traveling on this string has a frequency of 300 Hz and a wavelength of 0.45 m. What is the length of the string?

  4. Physics

    Suppose you pluck a string on a guitar and it produces the note A at a frequency of 440 Hz. Now, you press your finger down on the string against one of the frets, making this point the new end of the string. The newly shortened

You can view more similar questions or ask a new question.