Spring Semester 2005


Lab Five: Homework Three and More Practice Quizzes

There will be a few help questions about Homework Three here.

Here now are some questions for you to work on for next time:

Question 1.
What is the output produced by the following code when embedded in a complete program?
int x = 14;
while (x < 15)
  x = x + 1;
  System.out.print(x); 
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?
int x = 14;
while (x < 15)
  x = x + 1;
System.out.print(x); 
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 3.
What is the output produced by the following code when embedded in a complete program?
int x = 14;
while (x <= 15) {
  x = x + 1;
System.out.print(x); } 
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 4.
What is the output produced by the following code when embedded in a complete program?
int i;
for (i = 0; i < 3; i = i + 1)
  System.out.print(1);
System.out.print(0); 
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 5.
What is the output produced by the following code when embedded in a complete program?
int i;
for (i = 0; i < 3; i = i + 1) {
  System.out.print(1);
System.out.print(0); } 
Please type your answer in the following box:

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


Question 6.
What is the output produced by the following code when embedded in a complete program?
int x = 10, y = 3;
while (x > 0 && y > 0)
  x = x - y;
  System.out.print(x);
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 7.
What is the output produced by the following code when embedded in a complete program?
int x = 10, y = 3;
while (x > 0 && y > 0) {
  x = x - y;
} System.out.print(x);
Please type your answer in the following box:

Note that the program is the one from question 1 with an extra pair of curly brackets added. It may or may not be indented correctly so think about it carefully.


Question 8.
What is the output produced by the following code when embedded in a complete program?
int x = 10, y = 3;
while (x >= 0 && y > 0) {
  x = x - y;
  System.out.print(x);
}  
Please type your answer in the following box:

Note that the program is the one from question 1 with an extra pair of curly brackets added. It may or may not be indented correctly so think about it carefully.


Question 9.
What is the output produced by the following code when embedded in a complete program?
int x = 10;
while (x > 0)
  x = x - 3;
  System.out.print(x);
Please type your answer in the following box:


Question 10.
What is the output produced by the following code when embedded in a complete program?
int x = 10;
while (x > 0)
  x = x - 3;
System.out.print(x);
Please type your answer in the following box:


Question 11.
What is the output produced by the following code when embedded in a complete program?
int x = 10;
while (x > 0) {
  x = x - 3;
}
System.out.print(x);
Please type your answer in the following box:


Question 12.
What is the output produced by the following code when embedded in a complete program?
int x = 10;
while (x > 0) {
  x = x - 3;
System.out.print(x);
}
Please type your answer in the following box:


Question 13.
What is the output produced by the following code when embedded in a complete program?
int x = 10;
while (x < 0) {
  x = x - 3;
}
System.out.print(x);
Please type your answer in the following box:


For next time try to solve these problems and be ready to discuss the answers.


Last updated by Adrian German for A201/A597/I210 on Wed Feb 9 08:44:09 EST 2005