Using the example below. I want to see how to increase a number by calling a method occasionally. In this example, a hero would get armor, and his armor(totalArmor
) would increase each time new armor was picked up. I tried 2 outputs one that would be 0 and the other that I would hope would do 2. Thanks.
public static void main(String[] args) {
int totalArmor = 0;
int heroArmor = gainArmor(totalArmor);
System.out.println("\nTotal armor is " + totalArmor);
gainArmor(2);
System.out.println("\nTotal armor is " + totalArmor);
}
public static int gainArmor(int totalArmor) {
totalArmor++;
return totalArmor;
}