# Java Notes

# 'if' Exercise 1

Name: _________________________________

## Part I

What is the value of the variable n after the code in these questions? For these questions assume.

    int n = 0;
    int j = 7;

1. Value of n? __________
       if (j > 4) {
           n = 2;
       }
2. Value of n? __________
       if (j <= 4) {
           n = 2;
       }
3. Value of n? __________
       if (j > 4) {
           n = 2;
       } else {
           n = 3;
       }
4. Value of n? _______
       if (3 > n || j > 4) {
           n = 1;
       } else {
           n = 2;
       }
5. |  | Value of n? __________
       if (j > n) {
           n = 1;
           if (j > 4) {
               n = 2;
           } else {
               n = 3;
           }
       } else {
           n = 4;
           if (j%3 == 2) {
               n = 5;
           } else {
               n = 6;
           }
       }
6. Value of n? _______
       if (j > n && n!=0) {
           n = 1;
       } else {
           n = 2;
       }

## Part II

What would be the value of n assuming the following initial values for each of the above problems?

    int n = 5;
    int j = 4;

1. __________
2. __________
3. __________
4. __________
5. __________
6. __________