exam questions

Exam 98-388 All Questions

View all questions & answers for the 98-388 exam

Exam 98-388 topic 1 question 28 discussion

Actual exam question from Microsoft's 98-388
Question #: 28
Topic #: 1
[All 98-388 Questions]

HOTSPOT -
You are interviewing for a job as a Java developer. You need to demonstrate your understanding of switch statements.
For each of the following code segments, select Yes if the code segment can be changed to a switch statement with up to three case statements. Otherwise, select No.
NOTE: Each correct selection is worth one point.
Hot Area:

Show Suggested Answer Hide Answer
Suggested Answer:
References:
https://docs.oracle.com/javase/tutorial/java/nutsandbolts/switch.html

Comments

Chosen Answer:
This is a voting comment (?). It is better to Upvote an existing comment if you don't have anything to add.
Switch to a voting comment New
mtmoore
Highly Voted 4 years, 9 months ago
No, Yes, No. You can only test for equality in switch cases and the instructions said "up to 3" cases. The middle example is doable with cases for A and B and a default case. You would have to make a case for every possible year over 25 for the first example and all the possible fractional GPAs between 4.0 and 3.0 for the last example.
upvoted 10 times
Abhitera
4 years, 3 months ago
Correct
upvoted 1 times
...
...
rodrigoandrade
Most Recent 3 years, 11 months ago
Yes, Yes, Yes. Here is the example: public double discountByAge(int age) { double discount = -1.00; switch((age >= 25) ? 0 : (age >= 21 && age < 25) ? 1 : 2) { case 0: discount = 0.50; break; case 1: discount = 0.25; break; case 2: default: discount=0.0; break; } return discount; }
upvoted 2 times
...
alejandro355416
4 years, 1 month ago
int age; switch(age){ case(age >= 25): d = .5; break; case(age >= 21): d=.25; break; default: d=0 } YES char grade; switch(grade){ case(grade == A): message = "exceeds"; break; case(grade == B): message = "standard"; break; default: message = "improve"; YES -Does not work with doubles NO
upvoted 1 times
Mehal
4 years ago
First one is wrong give us compiletime error
upvoted 1 times
...
Girul
3 years, 7 months ago
Try it! double gpa = 3.2; int priority = 0; switch (gpa==4.0?1:gpa>=3.5?2:gpa>=2.5?3:0) { case 1: priority = 1; break; case 2: priority = 2; break; case 3: priority = 3; break; } System.out.println(priority);
upvoted 1 times
...
...
atro1233
4 years, 8 months ago
No, Yes, No
upvoted 3 times
...
mrunmayi
4 years, 8 months ago
switch doesn't work with double and string as well(except wrappers) in middle example switch holds string and in 3rd example switch holds double
upvoted 1 times
...
Community vote distribution
A (35%)
C (25%)
B (20%)
Other
Most Voted
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.

SaveCancel
Loading ...