Java中不能switch String变量,只能是char或者数字类型。
如果你非要这么做,就用别的语句如
if.....
else if.........
else if.........
else.......代替吧

解决方案 »

  1.   

    错,去看看JAVA的语法吧.
    1.switch(n),n必须是int或除long之外的整数
    2.case 后面只能有一个表达式,不能有几个.
    改成
    string c = .....;
    int intC = Integer.parseInt(c);
    switch(intC)
    {
    case 1:
      代码
      break;
    case 2:
      代码
      break;
    case 3:
    case 4:
    case 5:
      代码
      break;
    }
      

  2.   

    switch中不能使用String型。可使用char、int型。
    char i = 0;
    switch(c){
    case 0: break;
    case 1: break;
    }
      

  3.   

    char的本质为数字类型。The switch statement transfers control to one of several statements depending on the value of an expression.SwitchStatement:
    switch ( Expression ) SwitchBlockSwitchBlock:
    { SwitchBlockStatementGroupsopt SwitchLabelsopt }SwitchBlockStatementGroups:
    SwitchBlockStatementGroup
    SwitchBlockStatementGroups SwitchBlockStatementGroupSwitchBlockStatementGroup:
    SwitchLabels BlockStatementsSwitchLabels:
    SwitchLabel
    SwitchLabels SwitchLabelSwitchLabel:
    case ConstantExpression :
    default :The type of the Expression must be char, byte, short, or int, or a compile-time error occurs.
      

  4.   

    To  zhg_dragon(阿龙)
    上面的这段话来自《Java Language Specification Second Edition》http://java.sun.com/docs/books/jls/second_edition/html/j.title.doc.htmlTo 楼主
    你把字符串转为字符数组可以,但是这样还是不满足条件,要char不能是char[]。so 用我前面说的吧。
      

  5.   

    TO Norwaywoods(),我不说你错了,我是说楼主错了.不好意思....