IU Bloomington Evaluation Services and Testing

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);  
Please type your answer in the following box:

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); } 
Please type your answer in the following box:

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);
Please type your answer in the following box:


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);
Please type your answer in the following box:


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);
Please type your answer in the following box:

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);
Please type your answer in the following box:

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);
} 
Please type your answer in the following box:


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);
} 
Please type your answer in the following box:


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


Click to submit your answers.   Help


This activity is available between these dates and times: 07.08.10:00-08.11.19:59
It can be submitted a total of 30 times.
If it is a scored activity, the highest non-zero score will be counted.


Screen: TAKE_QUIZ
Last updated: Thu Mar 8 13:40:07 2001
URL: https://www.indiana.edu/~best/cgi-bin/quizsite/students.pl
Comments: best@indiana.edu
Copyright 2000, BEST & The Trustees of Indiana University