logo Practice-It logo

ifElseMystery1

Language/Type: Java if/else method basics mystery
Author: Kimberly Todd

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

public static void mystery1(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);
}
mystery1(8);
mystery1(-3);
mystery1(1);
mystery1(0);

You must log in before you can solve this problem.


Log In

If you do not understand how to solve a problem or why your solution doesn't work, please contact your TA or instructor.
If something seems wrong with the site (errors, slow performance, incorrect problems/tests, etc.), please

Is there a problem? Contact a site administrator.