Solved How does one figure out how many times one has to add a short to get the value of another short?

Discussion in 'Plugin Development' started by wacky3zaybxc, Aug 2, 2013.

Thread Status:
Not open for further replies.
  1. Offline

    wacky3zaybxc

    How does one figure out how many times one has to add a short to get the value of another short?

    I know, I know, it's a weirdly phrased question. But in more specifics without all the primitive types of Java...

    Basically, I have a short x, which we'll use the placeholder 7 for. I also have a short y, which I'll say is the number 5. And then, I have a short z, which I'll say is 236.

    Now, what I want to do, is get an integer that counts how many times I have to add the number y (5) to the number x (7) to get to the maximum value of z (236).

    Obviously, I could do that somewhat with a pencil and paper right now, but what I need is something that I can input the 3 values and it will give me the integer as the output - the number of times I have to add the value y to the number x to get to the maximum value of z.

    If you still don't understand what I'm doing, then a more visual example is:

    (Y * someint) + X = Z How would I get to someint?
     
  2. Offline

    SyTeck

    I don't really know what you want to do, but maybe you could do a loop like this:
    Code:java
    1. for(int i = 0; i < 100; i++) {
    2.  
    3. if((Y * i) + X == Z) {
    4.  
    5. return i;
    6.  
    7. }
    8. }
     
  3. Offline

    psycowithespn

    Basic algebra:
    (Y * someint) + X = Z
    Y * someint = Z - X
    someint = (Z - X) / Y
     
  4. Offline

    wacky3zaybxc

    Ack, and I just finished Algebra 2. Cheers!
     
Thread Status:
Not open for further replies.

Share This Page