logo CodeStepByStep logo

ifElseMystery1

Language/Type: Java if/else

For each call to the following method, indicate what output is produced.

public static void mystery(int n) {
    System.out.print(n + " ");
    if (n > 0) {
        n = n - 5;
    }
    if (n < 0) {
        n = n + 7;
    } else {
        n = n * 2;
    }
    System.out.println(n);
}
mystery(8);
mystery(-3);
mystery(1);
mystery(0);

You must log in before you can solve this problem.

Log In

Need help?

Stuck on an exercise? Contact your TA or instructor.

If something seems wrong with our site, please

Is there a problem? Contact us.