程序问答   发布时间:2022-06-02  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了如何前往下方的标签?大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

如何解决如何前往下方的标签??

开发过程中遇到如何前往下方的标签?的问题如何解决?下面主要结合日常开发的经验,给出你关于如何前往下方的标签?的解决方法建议,希望对你解决如何前往下方的标签?有所启发或帮助;

标签不能像这样工作。在Java中,没有任何goto label功能。当您有内部循环且需要breakcontinue有外部循环时,将使用标签,如以下示例所示:

outterloop:
for (int i = 0; i < 10; i++) {
    for (int j = 0; j < 10; j++) {
        // this would break the inner loop and go to the next outter loop iteration
        // break;

        // this would break the outter loop, thus exiting both loops
        // break outterloop;

        // this would jump to the next inner loop iteration
        // continue;

        // this would jump to the next outter loop iteration, exiting the inner loop
        // continue outterloop; 
    }
}

您需要的是在不使用标签的情况下改进代码结构以实现所需的功能。

https://docs.oracle.com/javase/tutorial/java/nutsandbolts/branch.html

解决方法

所以我有这个代码,我想当用户键入A来激活在此代码下面的while(attack)时,它就不能继续攻击;我在while(attack)上方放置了一个名为Attack:的标签,但它无法识别,因为稍后会对其进行声明。

String M2 = JOptionPane.showInputDialog(Name2 + "'s Turn. Here are your options\n 1.Invade \n 2.Buy \n 3.End Turn \n 4.Check Money Balance \n 5.Check Soldier Count \n 6.Citizen's Hapinness \n 7.Owned Islands \n 8.Check Rules","Type the Number of the action you want to take place");
                    if (M2.equals("1")) {
                        String Inv=JOptionPane.showInputDialog(null,"Open up the map and Check the island that you are in! If you dont remember the islands name type B to go back and then go into Owned Islands and come back! Then see the attack option you have and choose where you want to attack.Type A to Attack");
                        if(Inv.equalsIgnoreCase("A")){
                            Attack=false;
                            Attack=true;
                            continue attack;
                        }else{

                            continue P2Menu2;
                        }
                    }

这是播放器键入A时必须开始的代码。谢谢您的时间.. :)

 //Attack Phase    
        attack:
        while (Attack) {
        Random r = new Random();
        int R = r.nextInt(6 - 1) + 1;
        int R2 = r.nextInt(6 - 1) + 1;
        int R3 = r.nextInt(6 - 1) + 1;
        int R4 = r.nextInt(6 - 1) + 1;
        int R5 = r.nextInt(6 - 1) + 1;
        int R6 = r.nextInt(6 - 1) + 1;
        int totalr[] = {R,R2,R3,R4,R5,R6};

大佬总结

以上是大佬教程为你收集整理的如何前往下方的标签?全部内容,希望文章能够帮你解决如何前往下方的标签?所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。
标签: