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