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;
}
}
}
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;
}
}
}
然后输出:red
可是现在连javac都不行
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,就在这里乱来啊
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;
}}