answer is A, is tested :
int wd = 0;
String days[] = {"sun", "mon", "wed", "sat"};
for (String s : days) {
switch (s) {
case "sat":
case "sun":
wd--;
System.out.println(wd + " sun ");
break;
case "mon":
wd++;
System.out.println(wd + " mon ");
case "wed":
wd += 2;
System.out.println(wd + " wed ");
}
}
System.out.print(wd + " ");
result is
-1 sun
0 mon
2 wed
4 wed
3 sun
3
The array instantiation is wrong, it is {} instead of [] and this causes a compilation error. If the array was with {} it would compile. So the answer is letter D.
Testing in my IDE, the answer that most convinces me is the letter D. An error occurs in the attribution signal. When I remove the parentheses and insert braces the error disappears
Correct answer is A, result is 3
public class Test {
public static void main(String[] args) {
int wd = 0;
String days[] = {"sun", "mon", "wed", "sat"};
for (String s : days) {
switch (s) {
case "sat":
case "sun":
wd--;
break;
case "mon":
wd++;
case "wed":
wd = wd + 2;
}
}
System.out.print(wd + " ");
}
}
A voting comment increases the vote count for the chosen answer by one.
Upvoting a comment with a selected answer will also increase the vote count towards that answer by one.
So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.
DJava
Highly Voted 5 years, 5 months agoMPignaProTech
Most Recent 1 month, 4 weeks agoduydn
1 year, 3 months agodsms
1 year, 4 months agoRAADEL3IMLAK
1 year, 10 months agoakbiyik
2 years agoiSnover
2 years, 2 months agoiSnover
2 years, 2 months agoiSnover
2 years, 2 months agoLavz5
2 years, 3 months agohexadecimal82
2 years, 5 months agoarcher1903
2 years, 6 months agolnrdgst
2 years, 10 months agoEmilioDeBaku
3 years, 5 months agoSSJ5
3 years, 8 months agoOmegaric
4 years agoMelaena
4 years agopg13
4 years, 5 months ago