[Solved] java: changing value of integer to new value


Suppose the original code had been

int count;
count = 1;

This does two things. The first line creates a variable called count, of type int. The second line assigns a value to that variable.

Because it’s very common to assign a value to a variable as soon as it’s created, Java lets you combine these two commands into a single one, like this.

int count = 1;

This is just a shorthand way of writing the same thing. So it creates the variable and assigns the value.

But if you now follow it with a line such as

int count = 100;

then you’re trying to create a second variable with the same name as the first. This is not permitted. Instead, you only need to assign a new value to the existing variable. To do that, just write

count = 100;

solved java: changing value of integer to new value