小编ear*_*est的帖子

如何在java中的while循环中设置switch语句

我想在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 switch-statement

10
推荐指数
2
解决办法
4万
查看次数

if语句之外的变量访问

我试图在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)

java if-statement

5
推荐指数
2
解决办法
2万
查看次数

帮助在Java中将数组更改为单个变量

请帮忙.

我想添加这些选项,其中goodMan并购买蝙蝠,斧头或剑来对抗怪物.

如何创建这3个数组,然后从中获取单个变量.然后使用这些变量来影响游戏的结果?

  1. 蝙蝠最小伤害= 2最大伤害= 4成本= 3
  2. ax min damage = 4 max damage = 6 cost = 6
  3. 剑最小伤害= 6最大伤害= 8成本= 10
  4. 取消
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)

java arrays variables

0
推荐指数
1
解决办法
190
查看次数

标签 统计

java ×3

arrays ×1

if-statement ×1

switch-statement ×1

variables ×1