DO .. WHILE ..带SWITCH菜单

时间:2014-05-01 11:48:28

标签: java loops while-loop switch-statement

这是一个带有切换菜单的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');

1 个答案:

答案 0 :(得分:1)

do{

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