Results 1 to 11 of 11
Like Tree1Likes
  • 1 Post By Norm

Thread: Adding/Subtracting a int

  1. #1
    Alkor is offline Member
    Join Date
    Feb 2012
    Posts
    39
    Rep Power
    0

    Default Adding/Subtracting a int

    Okay, dumb question...

    Java Code:
    PlayerX --;
    How could I get this to subtract lets say 5.

    Thanks!

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,513
    Rep Power
    25

    Default Re: Adding/Subtracting a int

    Use an assignment statement.

  3. #3
    Alkor is offline Member
    Join Date
    Feb 2012
    Posts
    39
    Rep Power
    0

    Default Re: Adding/Subtracting a int

    If i assign it then i cant add more to it later on...

  4. #4
    jcarosella10 is offline Member
    Join Date
    Mar 2012
    Location
    Vestal, NY
    Posts
    36
    Rep Power
    0

    Default Re: Adding/Subtracting a int

    use the -= operator, which is equivalent to
    PlayerX = PlayerX - x;

    so do
    Java Code:
    PlayerX -= 5;

  5. #5
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,513
    Rep Power
    25

    Default Re: Adding/Subtracting a int

    i cant add more to it later on..
    You can add and subtract many times. That is why they are called variables.
    Bestsanchez likes this.

  6. #6
    jcarosella10 is offline Member
    Join Date
    Mar 2012
    Location
    Vestal, NY
    Posts
    36
    Rep Power
    0

    Default Re: Adding/Subtracting a int

    hahahahahaha
    if i could like that reply, i would.

  7. #7
    Alkor is offline Member
    Join Date
    Feb 2012
    Posts
    39
    Rep Power
    0

    Default Re: Adding/Subtracting a int

    Thanks jcarosella10, thats what i was looking for

  8. #8
    jcarosella10 is offline Member
    Join Date
    Mar 2012
    Location
    Vestal, NY
    Posts
    36
    Rep Power
    0

    Default Re: Adding/Subtracting a int

    your welcome. That works for all the operations like +=, *=, /=

  9. #9
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,513
    Rep Power
    25

    Default Re: Adding/Subtracting a int

    It is still an assignment statement.

  10. #10
    jcarosella10 is offline Member
    Join Date
    Mar 2012
    Location
    Vestal, NY
    Posts
    36
    Rep Power
    0

    Default Re: Adding/Subtracting a int

    I know. I don't think he knows though

  11. #11
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default Re: Adding/Subtracting a int

    @op, *=, +=, -=, /=, and %= are equivalent to

    Java Code:
    int x = 1;
    x = x + 1;
    In this snippet, I should +=, it should be obvious what the other ones look like.

Similar Threads

  1. negetive hours when subtracting dates
    By emyk in forum Advanced Java
    Replies: 1
    Last Post: 04-21-2011, 01:50 AM
  2. getting a date value from db and subtracting it in jsp
    By dayalan in forum JavaServer Pages (JSP) and JSTL
    Replies: 1
    Last Post: 03-14-2011, 09:05 AM
  3. Subtracting 2d Arrays
    By Spyderpig in forum New To Java
    Replies: 9
    Last Post: 03-11-2011, 05:12 AM
  4. Subtracting Strings
    By ravian in forum New To Java
    Replies: 7
    Last Post: 10-08-2009, 06:26 PM
  5. Subtracting Strings
    By lazygun247 in forum New To Java
    Replies: 6
    Last Post: 03-29-2009, 10:05 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •