Professional Documents
Culture Documents
These are short answer questions. State your answers concisely. Submit your answers to these questions as a
PDF document via Canvas by the due date.
1. Consider the following two Java loops:
while (x > 0) {
y++;
x--;
}
do {
y++;
x--;
} while (x > 0)
If x is set to 5 and y is set to zero before each loop, what are are the values of y at the end of each loop?
What if both variables are initialized to zero prior to each loop?
2.
int x = 0;
int y = 0;
while (x < 10) {
y++;
x++
}
int y = 0;
for(int x = 0; x < 10; x++) {
y++;
}
What are the values of y after the loops are completed? Are there any differences between the two
pieces of code?
3. Suppose you have the following methods:
void x(int [] a) {
for (int i = 0; i < a.length; i++)
a[i]++;
}
}
void y (int a) {
a++;
}
Are the values of b and c changed after the calls to method x and y? Why is there a difference?
4. Consider the following code:
int a[];
System.out.println(a[0]):
int [] b = {0,1,2,3,4,5,6,7};
for(int i : b)
System.out.println(i);
max(1, 2.0);
max(7, 8);
max(3.0, 2.1);