I am trying to access a variable outside an if statement in java. Variable axeMinDmg. Here is what I have but get an error message. I want to minDmg = axeMinDmg. thank
@SuppressWarnings("unused")
public static void main(String[] args)
throws IOException
{
int count = 1;
int goodTotal = 50;
int monTotal = 50;
int moneyAmt = 10;
int [] bat = {2, 4, 3};
int batMinDmg = bat[0];
int batMaxDmg = bat[1];
int batCost = bat[2];
int [] axe = {4, 6, 6};
int axeMinDmg = axe[0];
int axeMaxDmg = axe[1];
int axeCost = axe[2];
int [] sword = {6, 8, 10};
int swordMinDmg = sword[0];
int swordMaxDmg = sword[1];
int swordCost = sword[2];
System.out.println("Would you live to purchase a weapon (YES OR NO): ");
Scanner sc = new Scanner(System.in);
String name = sc.next();
if (name.equals("yes")){
System.out.println("Select Your Weapon \n axe \n bat \n sword : \n ");
Scanner wc = new Scanner(System.in);
String weapon = wc.next();
int minDmg = axeMinDmg;
if(weapon.equals("axe")){
int minDmg = axeMinDmg;
} else {
System.out.println();
}
source
share