Answered step by step
Verified Expert Solution
Link Copied!

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Concepts Of Programming Languages

Authors: Robert Sebesta

11th Edition

013394302X, 978-0133943023

More Books

Students also viewed these Programming questions

Question

What a statement of cash flows is. AppendixLO1

Answered: 1 week ago

Question

Verify Equation (9.36).

Answered: 1 week ago

Question

How is the NDAA used to shape defense policies indirectly?

Answered: 1 week ago

Question

What is the purpose of the finalize clause in Java?

Answered: 1 week ago