Change the value of an integer in java

Josh Hartigan picture Josh Hartigan · Sep 20, 2012 · Viewed 7.4k times · Source

I'm starting out programming with java and I'd like to make some games and various other things which require changing variables, especially integers. Let me give you an example.

    int Score = 0;

    if(coinCollected = 1){
        int Score = 1
    }

Now of course this is going to return 'int Score has already been defined', or whatever, but I don't want it to say that, since I want to REdefine the variable. I've tried @Override before the if statement and that didn't work, either. Does anyone know what to do?

Answer

kosa picture kosa · Sep 20, 2012

I think you want to update the value, if so, you don't need to re-define.

int Score = 0;

if(coinCollected == 1){
    // change the value
    Score = 1;
}