我想在while循环中进行切换,在每个switch语句中断while循环停止并请求输入如F,R,C,Q.下面的语句有效,但语句不会中断.请帮忙
public static void main(String[] args) throws IOException {
// start both with 1 point
int goodTotal = 50;
int monTotal = 50;
// input switch statement
while (goodTotal > 0 && monTotal > 0) {
System.out.print("Type a letter: ");
System.out.println("\n");
System.out.print("F: Go out and Fight ");
System.out.println("\n");
System.out.print("R: Rest ");
System.out.println("\n");
System.out.print("C: Check Stats ");
System.out.println("\n");
System.out.print("Q: Quit ");
int input = System.in.read();
System.out.println("You typed: " + (char) input);
switch (input) {
case 'f':
System.out.println("Continue the game");
break;
case …Run Code Online (Sandbox Code Playgroud) 我试图在java中的if语句之外访问变量.变量是axeMinDmg.这是我有,但得到一个错误.我想要minDmg = axeMinDmg.谢谢
@SuppressWarnings("unused")
public static void main(String[] args)
throws IOException
{
int count = 1;
// start both with 1 point
int goodTotal = 50;
int monTotal = 50;
// set amount of money that Goodman has
int moneyAmt = 10;
// setting array for bat
int [] bat = {2, 4, 3};
int batMinDmg = bat[0];
int batMaxDmg = bat[1];
int batCost = bat[2];
//setting array for axe
int [] axe = {4, 6, …Run Code Online (Sandbox Code Playgroud) 请帮忙.
我想添加这些选项,其中goodMan并购买蝙蝠,斧头或剑来对抗怪物.
如何创建这3个数组,然后从中获取单个变量.然后使用这些变量来影响游戏的结果?
public static void main(String[] args)
throws IOException
{
int count = 1;
// start both with 1 point
int goodTotal = 50;
int monTotal = 50;
int moneyAmt = 10;
// input switch statement
loop: while (goodTotal > 0 && monTotal > 0) {
System.out.print("Type a letter: ");
System.out.println("\n");
System.out.print("F: Go out and Fight ");
System.out.println("\n"); …Run Code Online (Sandbox Code Playgroud)