Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Rewrite this java code without the ++ and -- operators and without the switch, break, and continue statements that performs the same way. public static

Rewrite this java code without the ++ and -- operators and without the switch, break, and continue statements that performs the same way.

public static int fun(int a, int b) {

System.out.printf("a=%d,b=%d ", a, b); a += a-- + 2 * (++a + b);

System.out.printf("a=%d,b=%d ", a, b);

int x = b++ + ++a;

System.out.printf("a=%d,b=%d,x=%d ", a, b, x);

out:

for (int i = 1; i <= 100; i++) {

int j = b; if ((x + i) % 3 == 0) {

System.out.printf("continue: a=%d,b=%d,x=%d ", a, b, x);

continue; }

while (j > 1) {

if (x++ % 5 == 1) {

System.out.printf("break out: a=%d,b=%d,x=%d ", a, b, x);

break out;

}

j--;

if (j < a) {

System.out.printf("break: a=%d,b=%d,x=%d ", a, b, x);

break; }

x += i;

System.out.printf("a=%d,b=%d,x=%d ", a, b, x); } }

System.out.printf("a=%d,b=%d,x=%d ", a, b, x);

switch (a % 5) {

case 0:

x--;

case 1:

x++;

break;

case 2:

x -= b;

default:

x = x << 1; }

System.out.printf("a=%d,b=%d,x=%d ", a, b, x);

return x;

}

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_2

Step: 3

blur-text-image_3

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

Sams Teach Yourself Beginning Databases In 24 Hours

Authors: Ryan Stephens, Ron Plew

1st Edition

067232492X, 978-0672324925

More Books

Students also viewed these Databases questions

Question

The models used to analyse different national cultures.

Answered: 1 week ago

Question

The nature of the issues associated with expatriate employment.

Answered: 1 week ago