Using a variable defined in an If statement?
Sorry if this sounds dumb, but I can't seem to figure out how to use the
variable that I defined in the If statements.
import java.util.Scanner;
public class HelloWorld {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
//Prompt for Enchantment Type
System.out.println("Armor/Tool/Weapon");
//Wait for response
String input1 = scanner.nextLine();
if(input1 == "Armor"){
int type = 0;
}
else if(input1 == "Tool"){
int type = 1;
}
else if(input1 == "Weapon"){
int type = 2;
}
else {
int type = 3;
}
//This is where I need to access the String type
if(type == 1){
}
}
}
I can't figure out how to use the type string outside of it's block. I
know that I'm supposed to read on scope and stuff, but I'd really like
someone to just explain it to me.
No comments:
Post a Comment