L
lql0459
Unregistered / Unconfirmed
GUEST, unregistred user!
源码如下:谢谢解答!
import java.io.*;
public class exam2{
String color(int i){
int j;
for (j=0;
j<=i;
j++){
switch (j%2){
case 0: return "red";
break;
case 1: return "green";
break;
case 2: return "white";
break;
default: return "none color";
break;
}
}
}
public static void main(String args[]) {
exam2 abc=new exam2();
System.out.println(abc.color(9));
}
}
错误提示:
--------------------Configuration: java.exe <Default>--------------------
D:/Program Files/JCreator/MyProjects/exam2.java:8: unreachable statement
case 0: return "red";
break;
^
D:/Program Files/JCreator/MyProjects/exam2.java:9: unreachable statement
case 1: return "green";
break;
^
D:/Program Files/JCreator/MyProjects/exam2.java:10: unreachable statement
case 2: return "white";
break;
^
D:/Program Files/JCreator/MyProjects/exam2.java:11: unreachable statement
default: return "none color";
break;
^
D:/Program Files/JCreator/MyProjects/exam2.java:4: missing return statement
String color(int i){
^
5 errors
Process completed.
import java.io.*;
public class exam2{
String color(int i){
int j;
for (j=0;
j<=i;
j++){
switch (j%2){
case 0: return "red";
break;
case 1: return "green";
break;
case 2: return "white";
break;
default: return "none color";
break;
}
}
}
public static void main(String args[]) {
exam2 abc=new exam2();
System.out.println(abc.color(9));
}
}
错误提示:
--------------------Configuration: java.exe <Default>--------------------
D:/Program Files/JCreator/MyProjects/exam2.java:8: unreachable statement
case 0: return "red";
break;
^
D:/Program Files/JCreator/MyProjects/exam2.java:9: unreachable statement
case 1: return "green";
break;
^
D:/Program Files/JCreator/MyProjects/exam2.java:10: unreachable statement
case 2: return "white";
break;
^
D:/Program Files/JCreator/MyProjects/exam2.java:11: unreachable statement
default: return "none color";
break;
^
D:/Program Files/JCreator/MyProjects/exam2.java:4: missing return statement
String color(int i){
^
5 errors
Process completed.