Question: 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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!