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, 7 months agoSudhakar_Senthilkumar
Most Recent 1 month agoMPignaProTech
3 months agoduydn
1 year, 4 months agodsms
1 year, 5 months agoRAADEL3IMLAK
1 year, 11 months agoakbiyik
2 years, 1 month agoiSnover
2 years, 3 months agoiSnover
2 years, 3 months agoiSnover
2 years, 3 months agoLavz5
2 years, 4 months agohexadecimal82
2 years, 6 months agoarcher1903
2 years, 7 months agolnrdgst
2 years, 12 months agoEmilioDeBaku
3 years, 6 months agoSSJ5
3 years, 9 months agoOmegaric
4 years, 1 month agoMelaena
4 years, 1 month ago