简体   繁体   English

DO..WHILE.. 使用 SWITCH 菜单

[英]DO.. WHILE.. with SWITCH menu

Here is a do..while loop with switch menu..这是一个带有切换菜单的 do..while 循环..

I am trying to make the user be able to return to the menu which is我试图让用户能够返回到菜单

System.out.println("Options: (C)reate, (R)ead, (W)rite, (L)ist, (S)ave or (E)xit.        (*****)");

But after much trial and errors, I still cant get back to the main menu after choosing C, R, W, L or S.但是经过多次尝试和错误,我在选择C,R,W,L或S后仍然无法返回主菜单。

Below is a short snippet of the codes..下面是代码的一小段..

do {
    System.out.println("Options: (C)reate, (R)ead, (W)rite, (L)ist, (S)ave or (E)xit.   
    (*****)");
    Scanner switchC = new Scanner(System.in);
    System.out.println("Please enter your choice: ");
    choice = switchC.next().charAt(0);

    switch (Character.toUpperCase(choice)) {
        case 'C':
    System.out.println("C");
            break;
        case 'R':
            break;
        case 'W':
            break;
        case 'L':
            break;
        case 'S':
            break;
        case 'E':
            System.exit(1);
        default:
            System.out.println("Options: (C)reate, (R)ead, (W)rite, (L)ist, (S)ave or (E)xit.        (*****)");
        } 
} while(choice!='E');

try 尝试

do{

}
while(Character.toUpperCase(choice) !='E')

如何检查用户是否误按了任何选项?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM