public class Sample4_2{
public static void main(String args[]){
string a[]=new string[2];
a[0]="red";
a[1]="black";
a[2]="blue";
switch(args[])
{
case red:System.out.println(a[0]);break;
case black:System.out.println(a[1]);break;
case blue:System.out.println(a[2]);break;
}
}
}

解决方案 »

  1.   

    就是想,我JAVAC先过了之后,在JAVA程序时,后面写red,black,blue它能照常打印出来……
      

  2.   

    就是java Sample4_2 red
    然后输出:red
    可是现在连javac都不行
      

  3.   

    LZ是想命令行传参。不过LZ这代码也太……。string a[]=new string[2];后面却出现个a[2]="blue";而且switch()只能比较int或char这样的整数值,命令行传参传进去的都当作String。
      

  4.   

    switch()只能传递整数值,当然byte,char这些比int等级低的也可以传递,因为在执行的过程中自动转化成int类型
      

  5.   


    public class Sample4_2 {
    public static void main(String args[]) {
    String a[] = new String[3];
    a[0] = "red";
    a[1] = "black";
    a[2] = "blue";
    for (int i = 0; i < a.length; i++) {
    if (a[i].equals(args[0]))
    {
    System.out.println(a[i]);
    }
    }
    }
    }
    你这段代码问题很多:
    1.String应首字母大写
    2.数组大小定义错误,应该new String[3]
    3.switch里面不能用字符串变量
    4.case里面字符串应该加双引号
    帮你改了下,你这完全还没了解java,就在这里乱来啊
      

  6.   

    用枚举吧,String不能作为switch比较的对象的。public class Test{
    public static void main(String[] args){
    Color c = Color.Yellow;
    switch(c){
    case Red:
    System.out.println("Color: Red"); break;
    case Yellow:
    System.out.println("Color: Yellow");break;
    case White:
    System.out.println("Color: White");break;
    case Blue:
    System.out.println("Color: Blue");break;
    default:
    System.out.println("Color: Black");
    }
    } enum Color{
    Red,Yellow,White,Blue,Black;
    }}
      

  7.   

    不好意思,是只能传递int类型的