从do内部的开关出来,但没有布尔值,这可能吗? Java的

所以代码是关于在do while中给出输入的限制.
在这种情况下,你有3个机会继续.在那之后do while停止,你也可以让oportunitie停止任何键加上输入,但是当你开始时,你是否有oportunitie(这里进入开关)退出程序.
问题或我遇到的问题就在这里.

也许这可能没有布尔,或者可能改变或添加我还不知道的东西.对不起,我试着找到一个答案,但我看到的只是关于出一个布局左右的循环.不是这样的.

Scanner kb = new Scanner(system.in);
    // c = continue
    char c;
    // attempt to limit the input to 3 times
    int attempt = 3;
    // option = op
    int op = 0;

    do {
        do{
            System.out.println("Choose continue[0] or go out[1].");
            while  (!kb.hasNextInt()) {
                kb.nextLine();
                System.out.println("It's not a number.");                   
            }
            op = kb.nextInt();
        } while ( op <= -1 || op >= 2 );

        switch (op) {
        case 0:
            System.out.println("Continue!");
            break;
        case 1:     //here I tried; attempt = -1  
            break;  //is where I think it needs to be something
        default:
            break;
        }

        System.out.println("Do you wanna try again,"+attempt+" less?[c]+enter\n"
                + "Any other key + enter to exit.");
        c = kb.next(".").toupperCase().charat(0);
        attempt--;
    } while ( attempt > 0 && ( c == 'C' ) );
            //here also to put !( op == 0 )
    kb.close();

解决方法

如果用户选择0,您只需要求继续.

Scanner kb = new Scanner(system.in);
// c = continue
char c = 'a';
// attempt to limit the input to 3 times
int attempt = 3;
// option = op
int op = 0;

do {
    do{
        System.out.println("Choose continue[0] or go out[1].");
        while  (!kb.hasNextInt()) {
            kb.nextLine();
            System.out.println("It's not a number.");
        }
        op = kb.nextInt();
    } while ( op <= -1 || op >= 2 );

    switch (op) {
        case 0:
            System.out.println("Continue!");
            System.out.println("Do you wanna try again,"+attempt+" less?[c]+enter\n"
                    + "Any other key + enter to exit.");
            c = kb.next(".").toupperCase().charat(0);
            attempt--;
            break;
        case 1:
            attempt = -1;
            break;
        default:
            break;
    }
} while ( attempt > 0 && ( c == 'C' ) );
kb.close();

相关文章

Java中的String是不可变对象 在面向对象及函数编程语言中,不...
String, StringBuffer 和 StringBuilder 可变性 String不可变...
序列化:把对象转换为字节序列的过程称为对象的序列化. 反序...
先说结论,是对象!可以继续往下看 数组是不是对象 什么是对...
为什么浮点数 float 或 double 运算的时候会有精度丢失的风险...
面试题引入 这里引申出一个经典问题,看下面代码 Integer a ...