请帮我解决这个问题。我觉得这很简单,当我说完所有的时候,我可能会感到非常愚蠢。谢谢。
我尝试了很多东西,但似乎都没有用。 是的,我对Visual Basic比Java更熟悉,这就是我遇到这个问题的原因。
import java.util.Scanner;
public class YuGiOhLifePointCounter {
static Scanner sc = new Scanner(System.in);
public static void main(String[] args) {
double choice_1;
System.out.print("\nEnter the starting life points for player-1: ");
choice_1 = sc.nextDouble();
double storage_1;
storage_1 = choice_1;
double choice_2;
System.out.print("\nEnter the starting life points for player-2: ");
choice_2 = sc.nextDouble();
double storage_2;
storage_2 = choice_2;
double lp;
System.out.print("\nEnter a 6 to change the life-points of either player: ");
lp = sc.nextDouble();
double display_1 = choice_1;
double display_2 = choice_2;
while (lp == 6) {
/* Starting here*/
if (display_1 <== 0) {
System.out.println("Player-2 has won the game.");
System.exit(0);
}
if (display_2 <== 0) {
System.out.println("Player-1 has won the game.");
System.exit(0);
}
if (display_1 <> 0 && display_2 <> 0) {
/* these 3 if statements above are giving me illegal import errors, I can't figure out why. Thank You.*/
double choose_1_2;
System.out.print("\nEnter a 1 to change player-1's life-points, or enter a 2 to change player-2's life-points: ");
choose_1_2 = sc.nextDouble();
if (choose_1_2 == 1) {
double ch_1;
System.out.print("\nEnter the number subtracted from or added to player-1's life-points: ");
ch_1 = sc.nextDouble();
double c_1;
System.out.print("\nEnter a 1 to subtract this number from player-1's life-points, or enter a 2 to add this number to player-1's life-points: ");
c_1 = sc.nextDouble();
if (c_1 == 1) {
display_1 = storage_1 - ch_1;
System.out.println("\nPlayer-1's life-points are currently " + display_1);
}
if (c_1 == 2) {
display_1 = storage_1 + ch_1;
System.out.println("\nPlayer-1's life-points are currently " + display_1);
}
}
if (choose_1_2 == 2) {
double ch_2;
System.out.print("\nEnter the number subtracted from or added to player-2's life-points: ");
ch_2 = sc.nextDouble();
double c_2;
System.out.print("\nEnter a 1 to subtract this number from player-2's life-points, or enter a 2 to add this number to player-1's life-points: ");
c_2 = sc.nextDouble();
if (c_2 == 1) {
display_2 = storage_1 - ch_2;
System.out.println("\nPlayer-2's life-points are currently " + display_2);
}
if (c_2 == 2) {
display_2 = storage_1 + ch_2;
System.out.println("\nPlayer-2's life-points are currently " + display_2);
}
}
}
}
}
}
答案 0 :(得分:2)
if (display_1 <= = 0)
if (display_1 <> 0)
不确定你要做的是什么,但这些都不对。
如果您想检查display_1
小于0
,那么您需要:
if (display_1 < 0)
如果您想检查display_1
是否小于或等于0
,那么您需要:
if (display_1 <= 0)
如果您想检查display_1
等于0
,那么您需要:
if (display_1 == 0)
如果您想检查display_1
不等于0
,那么您需要:
if (display_1 != 0)