Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Rewrite the following pseudocode segment into a Java for statement (one for statement only). No unconditional branching statement (e.g. break, exit, ...) can be
Rewrite the following pseudocode segment into a Java for statement (one for statement only). No unconditional branching statement (e.g. break, exit, ...) can be used. (b) Assume k = 6, run your rewritten code (not the original code). What value of sum will be printed at the end? (show you code and output) k's value will be input by user //assume k and sum are of double type sum = 0 loop: if k > 10 then goto out k = k +1.5 sum += 2*k +1 goto loop out: print(sum) 4. (6 pts) Selection. (a) Rewrite the following code segment using a multiple-selection switch statement in Java. if (k == 1) || k == 6) result = 2* (++k) + 1; else if (k == 2 || k == 3 || k == 5) result = 3 * k-1; else if (k == 4) result = 4* k-1; else if (k> 7 && k < 14) result = (--k) -2 else result = k; print(result); //assume k is integer (b) Compared your rewritten code with the original code, which one has better readability? Which one better writability? (c) Describe the weakness in Java's switch statement and propose strategies (your creative design) to improve Java's switch statement.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started