gpt4 book ai didi

java - DO.. WHILE.. 使用 SWITCH 菜单

转载 作者:行者123 更新时间:2023-12-01 13:03:05 26 4
gpt4 key购买 nike

这是一个带有切换菜单的 do..while 循环..

我试图让用户能够返回到菜单

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

但是经过多次尝试,我在选择C、R、W、L或S后仍然无法返回主菜单。

下面是一小段代码..

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');

最佳答案

尝试

do{

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

关于java - DO.. WHILE.. 使用 SWITCH 菜单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23407051/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com