so im trying to make a mini game(?)
and theres somthing i want to do but i dont kno how
so here's my code
Scanner scan = new Scanner(System.in);
System.out.println("enter character name!");
String Name = scan.nextLine();
System.out.print("Nice name! hello ");
System.out.print(Name);
System.out.print("!");
System.out.println("look over there! thats ur rival coming!");
System.out.println("who is your rival name by the way?");
System.out.println("enter rival name!");
String rival = scan.nextLine();
int rival_hp = 100;
int Name_hp = 100;
//story start
System.out.println("ok ,beat him now!");
System.out.print("system: beat ");
System.out.print(rival);
System.out.print(" now!");
Scanner scan1 = new Scanner(System.in);
System.out.println("choose the following action");
System.out.println("1. low kick");
System.out.println("2. jab");
System.out.println("3. run");
String low_kick = "20";
String jab = "8";
int n = scan1.nextInt();
if( n == 1 ) { System.out.print(Name);
System.out.print(" used low kick!!,");
System.out.print("rival hp decreased to ");
Integer result = Integer.valueOf(rival_hp);
Integer result2 = Integer.valueOf(low_kick);
int rival_hp2 = result - result2;
System.out.print(rival_hp2); }
if( n == 2 ) { System.out.print(Name);
System.out.print(" used jab !!,");
System.out.print("rival hp decreased to ");
Integer result = Integer.valueOf(rival_hp);
Integer result2 = Integer.valueOf(jab);
int rival_hp2 = result - result2;
System.out.print(rival_hp2); }
if( n == 3 ) { System.out.print("u cant run idiot!!!");
}
the question is, how to make rival_hp2 variable useable for the next int i want to use out side the if{}?