I am building a RPG character generator and am having a semi-difficult time with the stats of the character. The reason I am having issues is this:
int base = 10;
int iStrengthStatPoints = scan.nextInt();
int iStrength = (base +iStrengthStatPoints);
It won’t compile because I am outputting the variable “iStrength” later in my code and it says cannot find symbol. I realize it is due to having iStrength being set to the value of base + iStrengthStatPoints. So I am wondering if there is a way I can assign a starting value to iStrengthStatPoints and then have the option to input a new value later on.
The thought I had was something like this:
int iStrengthStatPoints = 0;
int iStrengthStatPoints = scan.nextInt();
It would have the base value 0 but later on I could input an overriding value. Is this possible? If not is there a way to do something similar?
If you compiler is saying that it cannot find the symbol, you are trying to print
iStrengthout of its scope. Chances are you are declaring the variable in one method, giving it scope local to the method, and then trying to print it later in another method. This would be true even of variables declared in the class’s constructor.