logo Practice-It logo

if/else simulation

Language/Type: Java if/else mystery
Author: Kimberly Todd (on 2010/12/28)

For each call below to the following method, write the output that is produced, as it would appear on the console:

public static void mystery(int n) {
    System.out.print(n + " ");
    if (n > 10) {
        n = n / 2;
    } else {
        n = n + 7;
    }
    if (n * 2 < 25) {
        n = n + 10;
    }
    System.out.println(n);
}
mystery(40);
mystery(8);
mystery(0);
mystery(12);
mystery(20);

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.