Indiana University Bloomington Evaluation Services and Testing
QuizSite  Students
Quizzes · Tests · Evaluations · Surveys
 Activity: Practice_Three Student: dgerman (Adrian German) Instructor: dgerman Course: J201 Section: 4285
Question 1.
What is the output produced by the following code when embedded in a complete program?
```boolean x = false;
if (true)
System.out.print(0);
else
System.out.print(1);
x = x || !x;
if (x)
System.out.print(2);
else
System.out.print(3);  ```

Note that the program may or may not be indented correctly so think about it carefully.

Question 2.
What is the output produced by the following code when embedded in a complete program?
```boolean x = true;
if (true)
System.out.print(0);
else {
System.out.print(1);
x = x || !x;
if (x)
System.out.print(2);
else
System.out.print(3); } ```

Note that curly braces have been added, and the program may or may not be indented correctly so think about it carefully.

Question 3.
What is the output produced by the following code when embedded in a complete program?
```int x = 3;
if (x > 0) System.out.print(x + 1);
else if (x > 1) System.out.print(x);
else if (x > 2) System.out.print(x - 1);
else if (x > 3) System.out.print(2 * x);
else System.out.print(x * x);
```

Question 4.
What is the output produced by the following code when embedded in a complete program? (The code is identical to the one in the previous problem except one else has been removed).
```int x = 3;
if (x > 0) System.out.print(x + 1);
else if (x > 1) System.out.print(x);
else if (x > 2) System.out.print(x - 1);
else if (x > 3) System.out.print(2 * x);
else System.out.print(x * x);
```

Question 5.
What is the output produced by the following code when embedded in a complete program? (The code is identical to the one in the previous problem except one else has been removed).
```int x = 3;
if (x > 0) System.out.print(x + 1);
else if (x > 1) System.out.print(x);
else if (x > 2) System.out.print(x - 1);
else if (x > 3) System.out.print(2 * x);
else System.out.print(x * x);
```

Note: be careful with poor indentation.

Question 6.
What is the output produced by the following code when embedded in a complete program? (The code is identical to that of a previous problem, except one else has been removed).
```int x = 3;
if (x > 0) System.out.print(x + 1);
else if (x > 1) System.out.print(x);
else if (x > 2) System.out.print(x - 1);
else if (x > 3) System.out.print(2 * x);
else System.out.print(x * x);
```

Note: be careful with poor indentation.

Question 7.
What is the output produced by the following code when embedded in a complete program?
```if (false && false || true) {
System.out.print(100);
} else {
System.out.print(200);
} ```

Question 8.
What is the output produced by the following code when embedded in a complete program?
```if (false && (false || true)) {
System.out.print(100);
} else {
System.out.print(200);
} ```

Question 9.
Suppose that a `String` variable `a` holds a reference to an actual `String` object. What instance method defined in class `String` should be invoked on the reference `a` to get the character at position `0` in the `String` referred to by `a`?
(Type only the name of the method, with no arguments.)

Question 10.
You compile and run this program. What is the output that it produces?
```class One {
int a = 0;
void fun() {
int b = 0;
b += 1;
a += 1;
System.out.print(a + " " + b + " ");
}
public static void main(String[] args) {
One m = new One();
m.fun();
m.fun();
m.fun();
}
}```

`1 1 2 2 3 3`
`1 1 2 1 3 1`
`1 0 2 0 3 0`
`1 1 1 2 1 3`