# Change the value of an int

Discussion in 'Spigot Plugin Development' started by BillyBob9876, Jun 14, 2016.

1. ### BillyBob9876

I know this is EXTREMELY basic, but how do you change the value of an int?

int hi = 24
//Change the value to 82

I know you can do hi++ or hi+1 but

WAIT I JUST HAD AN IDEA
CAN YOU DO hi-28 OR hi-- OR DO MORE THAN ONE?

hi = <Int>

• Agree x 2

hi = 82;

• Agree x 1
4. ### v_M_v

hi = (3*27) + (7*2) - 12 - (1*3)

• Funny x 2
5. ### Stef

For integers you can do a few things to change its value.
Code (Text):
var = 10;
This will change the variable to 10.
Code (Text):
var += 10;
This will add 10 to the current value of var.
Code (Text):
var -= 10;
This will subtract 10 of the current value of var.
Code (Text):
var ×= 10;
This will multiply the current value of var by 10.
Code (Text):
var /= 10;
This will divide the current value of var by 10.
Code (Text):
var %= 10;
This will change var to the remainder of the value of var divided by 10.
Code (Text):
var++;
This will add one to the current value of var.
Code (Text):
var--;
This will subtract one of the current value of var.

Thanks guys!

8. ### VirusBrandon

hi = 82; //MIND BLOWN D:

Anyways, other ways to change the value are:

Direct Assignment:
hi = 82;
hi = hi - 20; // Result: 4 - Same as hi-=20;
hi = hi + 20; // Result: 44 - Same as hi +=20;

Increment:
hi++;

Decrement:
hi--;

Modified Operator:
hi+= 10; // Would result in 34 ( Starting value was 24)
hi-= 10; // Would result in 14 ( Starting value was 24)