错误:变量a,b,h2和h1可能尚未初始化。就像我说的,我是java的新手,只有3天,真的不明白为什么这不会工作...而且,类口袋妖怪我不会费心发布ebcasue它工作正常,错误真的没什么做它。
import java.util.Scanner;
public class Simplemon extends Pokemon {
Simplemon(int health, int strength, int speed, int type) {
super(health, strength, speed, type);
}
public static void main(String[] args) {
int s1;
int s2;
int h1;
int h2;
int sp1;
int sp2;
int t1;
int t2;
String a;
String b;
Scanner one = new Scanner(System.in);
Scanner two = new Scanner(System.in);
Scanner three = new Scanner(System.in);
Scanner four = new Scanner(System.in);
Pokemon charizard = new Pokemon(100, 2, 50, 1);
Pokemon blastoise = new Pokemon(150, 2, 150, 1);
Pokemon venasaur = new Pokemon(300, 2, 100, 1);
System.out.println("Hello, Welcome to Simplemon!");
System.out.println("Player One, Please select your pokemon.");
int x = one.nextInt();
System.out.println("Player Two, Please select your pokemon.");
int y = two.nextInt();
if (x == 1) {
s1 = charizard.strength;
h1 = charizard.health;
sp1 = charizard.speed;
t1 = charizard.type;
a = "charizard";
} else if (x == 2) {
s1 = blastoise.strength;
h1 = blastoise.health;
sp1 = blastoise.speed;
t1 = blastoise.type;
a = "blastoise";
} else if (x == 3) {
s1 = venasaur.strength;
h1 = venasaur.health;
sp1 = venasaur.speed;
t1 = venasaur.type;
a = "venasaur";
}
if (y == 1) {
s2 = charizard.strength;
h2 = charizard.health;
sp2 = charizard.speed;
t2 = charizard.type;
b = "charizard";
} else if (y == 2) {
s2 = blastoise.strength;
h2 = blastoise.health;
sp2 = blastoise.speed;
t2 = blastoise.type;
b = "blastoise";
} else if (y == 3) {
s2 = venasaur.strength;
h2 = venasaur.health;
sp2 = venasaur.speed;
t2 = venasaur.type;
b = "venasaur";
}
System.out.println(a + " begins the fight against " + b);
h2 = h2 - s1;
System.out.println(a + " does " + s1 + " damage to " +
b + " and " + b + " has " + s2 + " left.");
}
}
答案 0 :(得分:0)
您需要将变量设置为某个初始值。
String a = "";
String b = "";
int h1 = "";
int h2 = "";