Deck 1: Introduction to Java Programming

Full screen (f)
exit full mode
Question
Programming
Write a static method named sequenceSum that prints terms of the following mathematical sequence:

1+12+13+14+15+16+1+\frac{1}{2}+\frac{1}{3}+\frac{1}{4}+\frac{1}{5}+\frac{1}{6}+\ldots  (also written as i=11j ) \text { (also written as } \sum_{i=1}^{\infty} \frac{1}{j} \text { ) }
Your method should accept a real number as a parameter representing a limit, and should add and print terms of the sequence until the sum of terms meets or exceeds that limit. For example, if your method is passed 2.0, print terms until the sum of those terms is at ≥ 2.0. You should round your answer to 3 digits past the decimal point.
The following is the output from the call sequenceSum(2.0);
1 + 1/2 + 1/3 + 1/4 = 2.083
(Despite the fact that the terms keep getting smaller, the sequence can actually produce an arbitrarily large sum if enough terms are added.) If your method is passed a value less than 1.0, no output should be produced. You must match the output format shown exactly; note the spaces and pluses separating neighboring terms. Other sample calls:
 Calls  sequenceSum (0.0); sequenceSum (1.0); sequenceSum (1.5); Output 1=1.0001+1/2=1.500\begin{array}{l|l|l|l}\text { Calls } & \text { sequenceSum }(0.0) ; & \text { sequenceSum }(1.0) ; & \text { sequenceSum }(1.5) ; \\\hline \text { Output } & & 1=1.000 & 1+1 / 2=1.500\end{array}  Call  sequenceSum (2.7); Output 1+1/2+1/3+1/4+1/5+1/6+1/7+1/8=2.718\begin{array}{l|l}\text { Call } & \text { sequenceSum }(2.7) ; \\\hline \text { Output } & 1+1 / 2+1 / 3+1 / 4+1 / 5+1 / 6+1 / 7+1 / 8=2.718\end{array}
Use Space or
up arrow
down arrow
to flip the card.
Question
Expressions
For each expression in the left-hand column, indicate its value in the right-hand column. Be sure to list a constant of appropriate type (e.g., 7.0 rather than 7 for a double, Strings in quotes, true/false for a boolean).
0||4==9 \%5| |1+1<1-1 & \underline{ \text { }} \underline{ \text { }} \underline{ \text { }} \underline{ \text { }} \underline{ \text { }} \underline{ \text { }} \end{array}">Expression Value 34+56+72      1.52.0+(5.5/2)+5/4      23%5+31/4%317%(16%10)      "1"+2+3+"4"+56+"77"+(8+9)      345/10/355/5/6+10/(5/2.0)      1/2>04==9%51+1<11      \begin{array}{l}\underline{ \text {Expression } }& \underline{ \text {Value }} \\3 * 4+5 * 6+7 *-2 & \underline{ \text { }} \underline{ \text { }} \underline{ \text { }} \underline{ \text { }} \underline{ \text { }} \underline{ \text { }} \\1.5 * 2.0+(5.5 / 2)+5 / 4 & \underline{ \text { }} \underline{ \text { }} \underline{ \text { }} \underline{ \text { }} \underline{ \text { }} \underline{ \text { }}\\23 \% 5+31 / 4 \% 3-17 \% (16 \% 10) & \underline{ \text { }} \underline{ \text { }} \underline{ \text { }} \underline{ \text { }} \underline{ \text { }} \underline{ \text { }}\\" 1 "+2+3+"4 "+5 * 6+"77"+(8+9) & \underline{ \text { }} \underline{ \text { }} \underline{ \text { }} \underline{ \text { }} \underline{ \text { }} \underline{ \text { }} \\345 / 10 / 3 * 55 / 5 / 6+10 /(5 / 2.0) & \underline{ \text { }} \underline{ \text { }} \underline{ \text { }} \underline{ \text { }} \underline{ \text { }} \underline{ \text { }} \\1 / 2>0||4==9 \%5| |1+1<1-1 & \underline{ \text { }} \underline{ \text { }} \underline{ \text { }} \underline{ \text { }} \underline{ \text { }} \underline{ \text { }} \end{array}
Question
Parameter Mystery
At the bottom of the page, write the output produced by the following program.
public class ParameterMystery {
public static void main(String[] args) {
String x = "java";
String y = "tyler";
String z = "tv";
String rugby = "hamburger";
String java = "donnie";
hamburger(x, y, z);
hamburger(z, x, y);
hamburger("rugby", z, java);
hamburger(y, rugby, "x");
hamburger(y, y, "java");
}
public static void hamburger(String y, String z, String x) {
System.out.println(z + " and " + x + " like " + y);
}
}
Question
Programming
Write a static method named hasMidpoint that accepts three integers as parameters and returns true if one of the integers is the midpoint between the other two integers; that is, if one integer is exactly halfway between them. Your method should return false if no such midpoint relationship exists.
The integers could be passed in any order; the midpoint could be the 1st, 2nd, or 3rd. You must check all cases.
Calls such as the following should return true:hasmidpoint (4,6,8) hasmidpoint (2,10,6) hasmidpoint (8,8,8) hasmidpoint (25,10,-5)Calls such as the following should return false :hasmidpoint (3,1,3) hasmidpoint (1,3,1) hasmidpoint (21,9,58) hasmidpoint (2,8,16)\begin{array}{c}\begin{array}{}\text{Calls such as the following should return true:}\\ \text{hasmidpoint (4,6,8)}\\\text{ hasmidpoint (2,10,6)}\\\text{ hasmidpoint (8,8,8)}\\\text{ hasmidpoint (25,10,-5)}\end{array}\begin{array}{}\text{Calls such as the following should return false :}\\ \text{hasmidpoint (3,1,3)}\\\text{ hasmidpoint (1,3,1)}\\\text{ hasmidpoint (21,9,58)}\\\text{ hasmidpoint (2,8,16)}\end{array}\end{array}
Question
(Despite the fact that the terms keep getting smaller, the sequence can actually produce an arbitrarily large sum if enough terms are added.) If your method is passed a value less than 1.0, no output should be produced. You must match the output format shown exactly; note the spaces and pluses separating neighboring terms. Other sample calls:
(Despite the fact that the terms keep getting smaller, the sequence can actually produce an arbitrarily large sum if enough terms are added.) If your method is passed a value less than 1.0, no output should be produced. You must match the output format shown exactly; note the spaces and pluses separating neighboring terms. Other sample calls:     Programming Write a static method named favoriteLetter that accepts two parameters: a Scanner for the console, and a favorite letter represented as a one-letter String. The method repeatedly prompts the user until two consecutive words are entered that start with that letter. The method then prints a message showing the last word typed. You may assume that the user will type a single-word response to each prompt. Your code should be case-sensitive; for example, if the favorite letter is a, you should not stop prompting if the user types words that start with an A. For example, the following logs represent the output from two calls to your method: (User input is underlined.)  <div style=padding-top: 35px> (Despite the fact that the terms keep getting smaller, the sequence can actually produce an arbitrarily large sum if enough terms are added.) If your method is passed a value less than 1.0, no output should be produced. You must match the output format shown exactly; note the spaces and pluses separating neighboring terms. Other sample calls:     Programming Write a static method named favoriteLetter that accepts two parameters: a Scanner for the console, and a favorite letter represented as a one-letter String. The method repeatedly prompts the user until two consecutive words are entered that start with that letter. The method then prints a message showing the last word typed. You may assume that the user will type a single-word response to each prompt. Your code should be case-sensitive; for example, if the favorite letter is a, you should not stop prompting if the user types words that start with an A. For example, the following logs represent the output from two calls to your method: (User input is underlined.)  <div style=padding-top: 35px>
Programming
Write a static method named favoriteLetter that accepts two parameters: a Scanner for the console, and a favorite letter represented as a one-letter String. The method repeatedly prompts the user until two consecutive words are entered that start with that letter. The method then prints a message showing the last word typed.
You may assume that the user will type a single-word response to each prompt. Your code should be case-sensitive; for example, if the favorite letter is a, you should not stop prompting if the user types words that start with an A. For example, the following logs represent the output from two calls to your method: (User input is underlined.)
(Despite the fact that the terms keep getting smaller, the sequence can actually produce an arbitrarily large sum if enough terms are added.) If your method is passed a value less than 1.0, no output should be produced. You must match the output format shown exactly; note the spaces and pluses separating neighboring terms. Other sample calls:     Programming Write a static method named favoriteLetter that accepts two parameters: a Scanner for the console, and a favorite letter represented as a one-letter String. The method repeatedly prompts the user until two consecutive words are entered that start with that letter. The method then prints a message showing the last word typed. You may assume that the user will type a single-word response to each prompt. Your code should be case-sensitive; for example, if the favorite letter is a, you should not stop prompting if the user types words that start with an A. For example, the following logs represent the output from two calls to your method: (User input is underlined.)  <div style=padding-top: 35px>
Question
If/Else Simulation
For each call of the method below, write the value that is returned:
public static int mystery(int a, int b) {
int c;
if (a > b) {
c = a;
} else if (b % a == 0) {
c = b;
} else {
c = b + (a - (b % a));
}
return c;
}
 Method Call  Value Returned mystery (4,2)       mystery (5,4)       mystery (5,13)       mystery (5,17)       mystery (4,8)      \begin{array}{l}\underline{ \text { Method Call } }& \underline{ \text { Value Returned}} \\\text { mystery }(4,2) & \underline{ \text { }} \underline{ \text { }} \underline{ \text { }} \underline{ \text { }} \underline{ \text { }} \underline{ \text { }} \\\text { mystery }(5,4) & \underline{ \text { }} \underline{ \text { }} \underline{ \text { }} \underline{ \text { }} \underline{ \text { }} \underline{ \text { }}\\\text { mystery }(5,13) & \underline{ \text { }} \underline{ \text { }} \underline{ \text { }} \underline{ \text { }} \underline{ \text { }} \underline{ \text { }}\\\text { mystery }(5,17) & \underline{ \text { }} \underline{ \text { }} \underline{ \text { }} \underline{ \text { }} \underline{ \text { }} \underline{ \text { }} \\\text { mystery }(4,8) & \underline{ \text { }} \underline{ \text { }} \underline{ \text { }} \underline{ \text { }} \underline{ \text { }} \underline{ \text { }} \end{array}
Question
While Loop Simulation
For each call of the method below, write the output that is printed:
public static void mystery(int i, int j) {
while (i != 0 && j != 0) {
i = i / j;
j = (j - 1) / 2;
System.out.print(i + " " + j + " ");
}
System.out.println(i);
}
 Method Call  Output mystery (5,0)       mystery (3,2)       mystery (16,5)       mystery (80,9)       mystery (1600,40)      \begin{array}{l}\underline{ \text { Method Call } }& \underline{ \text { Output}} \\\text { mystery }(5,0) & \underline{ \text { }} \underline{ \text { }} \underline{ \text { }} \underline{ \text { }} \underline{ \text { }} \underline{ \text { }} \\\text { mystery }(3,2) & \underline{ \text { }} \underline{ \text { }} \underline{ \text { }} \underline{ \text { }} \underline{ \text { }} \underline{ \text { }}\\\text { mystery }(16,5) & \underline{ \text { }} \underline{ \text { }} \underline{ \text { }} \underline{ \text { }} \underline{ \text { }} \underline{ \text { }}\\\text { mystery }(80,9) & \underline{ \text { }} \underline{ \text { }} \underline{ \text { }} \underline{ \text { }} \underline{ \text { }} \underline{ \text { }} \\\text { mystery }(1600,40) & \underline{ \text { }} \underline{ \text { }} \underline{ \text { }} \underline{ \text { }} \underline{ \text { }} \underline{ \text { }} \end{array}
Question
Assertions
For the following method, identify each of the three assertions in the table below as being either ALWAYS true, NEVER true or SOMETIMES true / sometimes false at each labeled point in the code. (You may abbreviate these choices as A/N/S respectively.)
public static int mystery(int x) {
int y = 1;
int z = 0;
// Point A
while (y <= x) {
// Point B
y = y * 10;
z++;
// Point C
}
// Point D
z--;
// Point E
return z;
}
y>xz<0z>0 Point A  Point B  Point C  Point D  Point E \begin{array}{|c|c|c|c|} \hline& \mathrm{y}>\mathrm{x} & z<0 & z>0 \\\hline \text { Point A } & & & \\\hline \text { Point B } & & & \\\hline \text { Point C } & & & \\\hline \text { Point D } & & & \\\hline \text { Point E } & & & \\\hline\end{array}
Unlock Deck
Sign up to unlock the cards in this deck!
Unlock Deck
Unlock Deck
1/8
auto play flashcards
Play
simple tutorial
Full screen (f)
exit full mode
Deck 1: Introduction to Java Programming
1
Programming
Write a static method named sequenceSum that prints terms of the following mathematical sequence:

1+12+13+14+15+16+1+\frac{1}{2}+\frac{1}{3}+\frac{1}{4}+\frac{1}{5}+\frac{1}{6}+\ldots  (also written as i=11j ) \text { (also written as } \sum_{i=1}^{\infty} \frac{1}{j} \text { ) }
Your method should accept a real number as a parameter representing a limit, and should add and print terms of the sequence until the sum of terms meets or exceeds that limit. For example, if your method is passed 2.0, print terms until the sum of those terms is at ≥ 2.0. You should round your answer to 3 digits past the decimal point.
The following is the output from the call sequenceSum(2.0);
1 + 1/2 + 1/3 + 1/4 = 2.083
(Despite the fact that the terms keep getting smaller, the sequence can actually produce an arbitrarily large sum if enough terms are added.) If your method is passed a value less than 1.0, no output should be produced. You must match the output format shown exactly; note the spaces and pluses separating neighboring terms. Other sample calls:
 Calls  sequenceSum (0.0); sequenceSum (1.0); sequenceSum (1.5); Output 1=1.0001+1/2=1.500\begin{array}{l|l|l|l}\text { Calls } & \text { sequenceSum }(0.0) ; & \text { sequenceSum }(1.0) ; & \text { sequenceSum }(1.5) ; \\\hline \text { Output } & & 1=1.000 & 1+1 / 2=1.500\end{array}  Call  sequenceSum (2.7); Output 1+1/2+1/3+1/4+1/5+1/6+1/7+1/8=2.718\begin{array}{l|l}\text { Call } & \text { sequenceSum }(2.7) ; \\\hline \text { Output } & 1+1 / 2+1 / 3+1 / 4+1 / 5+1 / 6+1 / 7+1 / 8=2.718\end{array}
(one solution shown)
public static void sequenceSum(double limit) {
if (limit >= 1) {
System.out.print("1");
int denomenator = 1;
double sum = 1.0;
while (sum < limit) {
denomenator++;
sum += 1.0 / denomenator;
System.out.print(" + 1/" + denomenator);
}
System.out.printf(" = %.3f\n", sum);
}
}
2
Expressions
For each expression in the left-hand column, indicate its value in the right-hand column. Be sure to list a constant of appropriate type (e.g., 7.0 rather than 7 for a double, Strings in quotes, true/false for a boolean).
0||4==9 \%5| |1+1<1-1 & \underline{ \text { }} \underline{ \text { }} \underline{ \text { }} \underline{ \text { }} \underline{ \text { }} \underline{ \text { }} \end{array}">Expression Value 34+56+72      1.52.0+(5.5/2)+5/4      23%5+31/4%317%(16%10)      "1"+2+3+"4"+56+"77"+(8+9)      345/10/355/5/6+10/(5/2.0)      1/2>04==9%51+1<11      \begin{array}{l}\underline{ \text {Expression } }& \underline{ \text {Value }} \\3 * 4+5 * 6+7 *-2 & \underline{ \text { }} \underline{ \text { }} \underline{ \text { }} \underline{ \text { }} \underline{ \text { }} \underline{ \text { }} \\1.5 * 2.0+(5.5 / 2)+5 / 4 & \underline{ \text { }} \underline{ \text { }} \underline{ \text { }} \underline{ \text { }} \underline{ \text { }} \underline{ \text { }}\\23 \% 5+31 / 4 \% 3-17 \% (16 \% 10) & \underline{ \text { }} \underline{ \text { }} \underline{ \text { }} \underline{ \text { }} \underline{ \text { }} \underline{ \text { }}\\" 1 "+2+3+"4 "+5 * 6+"77"+(8+9) & \underline{ \text { }} \underline{ \text { }} \underline{ \text { }} \underline{ \text { }} \underline{ \text { }} \underline{ \text { }} \\345 / 10 / 3 * 55 / 5 / 6+10 /(5 / 2.0) & \underline{ \text { }} \underline{ \text { }} \underline{ \text { }} \underline{ \text { }} \underline{ \text { }} \underline{ \text { }} \\1 / 2>0||4==9 \%5| |1+1<1-1 & \underline{ \text { }} \underline{ \text { }} \underline{ \text { }} \underline{ \text { }} \underline{ \text { }} \underline{ \text { }} \end{array}
0||4==9 \%5| |1+1<1-1 & true \end{array}">Expression Value 34+56+72281.52.0+(5.5/2)+5/46.7523%5+31/4%317%(16%10)1"1"+2+3+"4"+56+"77"+(8+9)"123430717"345/10/355/5/6+10/(5/2.0)24.01/2>04==9%51+1<11true\begin{array}{l|}\underline{ \text {Expression } }& \underline{ \text {Value }} \\3 * 4+5 * 6+7 *-2 & 28 \\1.5 * 2.0+(5.5 / 2)+5 / 4 & 6.75\\23 \% 5+31 / 4 \% 3-17 \% (16 \% 10) & -1\\" 1 "+2+3+"4 "+5 * 6+"77"+(8+9) & "123430717"\\345 / 10 / 3 * 55 / 5 / 6+10 /(5 / 2.0) & 24.0\\1 / 2>0||4==9 \%5| |1+1<1-1 & true \end{array}
3
Parameter Mystery
At the bottom of the page, write the output produced by the following program.
public class ParameterMystery {
public static void main(String[] args) {
String x = "java";
String y = "tyler";
String z = "tv";
String rugby = "hamburger";
String java = "donnie";
hamburger(x, y, z);
hamburger(z, x, y);
hamburger("rugby", z, java);
hamburger(y, rugby, "x");
hamburger(y, y, "java");
}
public static void hamburger(String y, String z, String x) {
System.out.println(z + " and " + x + " like " + y);
}
}
tyler and tv like java
java and tyler like tv
tv and donnie like rugby
hamburger and x like tyler
tyler and java like tyler
4
Programming
Write a static method named hasMidpoint that accepts three integers as parameters and returns true if one of the integers is the midpoint between the other two integers; that is, if one integer is exactly halfway between them. Your method should return false if no such midpoint relationship exists.
The integers could be passed in any order; the midpoint could be the 1st, 2nd, or 3rd. You must check all cases.
Calls such as the following should return true:hasmidpoint (4,6,8) hasmidpoint (2,10,6) hasmidpoint (8,8,8) hasmidpoint (25,10,-5)Calls such as the following should return false :hasmidpoint (3,1,3) hasmidpoint (1,3,1) hasmidpoint (21,9,58) hasmidpoint (2,8,16)\begin{array}{c}\begin{array}{}\text{Calls such as the following should return true:}\\ \text{hasmidpoint (4,6,8)}\\\text{ hasmidpoint (2,10,6)}\\\text{ hasmidpoint (8,8,8)}\\\text{ hasmidpoint (25,10,-5)}\end{array}\begin{array}{}\text{Calls such as the following should return false :}\\ \text{hasmidpoint (3,1,3)}\\\text{ hasmidpoint (1,3,1)}\\\text{ hasmidpoint (21,9,58)}\\\text{ hasmidpoint (2,8,16)}\end{array}\end{array}
Unlock Deck
Unlock for access to all 8 flashcards in this deck.
Unlock Deck
k this deck
5
(Despite the fact that the terms keep getting smaller, the sequence can actually produce an arbitrarily large sum if enough terms are added.) If your method is passed a value less than 1.0, no output should be produced. You must match the output format shown exactly; note the spaces and pluses separating neighboring terms. Other sample calls:
(Despite the fact that the terms keep getting smaller, the sequence can actually produce an arbitrarily large sum if enough terms are added.) If your method is passed a value less than 1.0, no output should be produced. You must match the output format shown exactly; note the spaces and pluses separating neighboring terms. Other sample calls:     Programming Write a static method named favoriteLetter that accepts two parameters: a Scanner for the console, and a favorite letter represented as a one-letter String. The method repeatedly prompts the user until two consecutive words are entered that start with that letter. The method then prints a message showing the last word typed. You may assume that the user will type a single-word response to each prompt. Your code should be case-sensitive; for example, if the favorite letter is a, you should not stop prompting if the user types words that start with an A. For example, the following logs represent the output from two calls to your method: (User input is underlined.)  (Despite the fact that the terms keep getting smaller, the sequence can actually produce an arbitrarily large sum if enough terms are added.) If your method is passed a value less than 1.0, no output should be produced. You must match the output format shown exactly; note the spaces and pluses separating neighboring terms. Other sample calls:     Programming Write a static method named favoriteLetter that accepts two parameters: a Scanner for the console, and a favorite letter represented as a one-letter String. The method repeatedly prompts the user until two consecutive words are entered that start with that letter. The method then prints a message showing the last word typed. You may assume that the user will type a single-word response to each prompt. Your code should be case-sensitive; for example, if the favorite letter is a, you should not stop prompting if the user types words that start with an A. For example, the following logs represent the output from two calls to your method: (User input is underlined.)
Programming
Write a static method named favoriteLetter that accepts two parameters: a Scanner for the console, and a favorite letter represented as a one-letter String. The method repeatedly prompts the user until two consecutive words are entered that start with that letter. The method then prints a message showing the last word typed.
You may assume that the user will type a single-word response to each prompt. Your code should be case-sensitive; for example, if the favorite letter is a, you should not stop prompting if the user types words that start with an A. For example, the following logs represent the output from two calls to your method: (User input is underlined.)
(Despite the fact that the terms keep getting smaller, the sequence can actually produce an arbitrarily large sum if enough terms are added.) If your method is passed a value less than 1.0, no output should be produced. You must match the output format shown exactly; note the spaces and pluses separating neighboring terms. Other sample calls:     Programming Write a static method named favoriteLetter that accepts two parameters: a Scanner for the console, and a favorite letter represented as a one-letter String. The method repeatedly prompts the user until two consecutive words are entered that start with that letter. The method then prints a message showing the last word typed. You may assume that the user will type a single-word response to each prompt. Your code should be case-sensitive; for example, if the favorite letter is a, you should not stop prompting if the user types words that start with an A. For example, the following logs represent the output from two calls to your method: (User input is underlined.)
Unlock Deck
Unlock for access to all 8 flashcards in this deck.
Unlock Deck
k this deck
6
If/Else Simulation
For each call of the method below, write the value that is returned:
public static int mystery(int a, int b) {
int c;
if (a > b) {
c = a;
} else if (b % a == 0) {
c = b;
} else {
c = b + (a - (b % a));
}
return c;
}
 Method Call  Value Returned mystery (4,2)       mystery (5,4)       mystery (5,13)       mystery (5,17)       mystery (4,8)      \begin{array}{l}\underline{ \text { Method Call } }& \underline{ \text { Value Returned}} \\\text { mystery }(4,2) & \underline{ \text { }} \underline{ \text { }} \underline{ \text { }} \underline{ \text { }} \underline{ \text { }} \underline{ \text { }} \\\text { mystery }(5,4) & \underline{ \text { }} \underline{ \text { }} \underline{ \text { }} \underline{ \text { }} \underline{ \text { }} \underline{ \text { }}\\\text { mystery }(5,13) & \underline{ \text { }} \underline{ \text { }} \underline{ \text { }} \underline{ \text { }} \underline{ \text { }} \underline{ \text { }}\\\text { mystery }(5,17) & \underline{ \text { }} \underline{ \text { }} \underline{ \text { }} \underline{ \text { }} \underline{ \text { }} \underline{ \text { }} \\\text { mystery }(4,8) & \underline{ \text { }} \underline{ \text { }} \underline{ \text { }} \underline{ \text { }} \underline{ \text { }} \underline{ \text { }} \end{array}
Unlock Deck
Unlock for access to all 8 flashcards in this deck.
Unlock Deck
k this deck
7
While Loop Simulation
For each call of the method below, write the output that is printed:
public static void mystery(int i, int j) {
while (i != 0 && j != 0) {
i = i / j;
j = (j - 1) / 2;
System.out.print(i + " " + j + " ");
}
System.out.println(i);
}
 Method Call  Output mystery (5,0)       mystery (3,2)       mystery (16,5)       mystery (80,9)       mystery (1600,40)      \begin{array}{l}\underline{ \text { Method Call } }& \underline{ \text { Output}} \\\text { mystery }(5,0) & \underline{ \text { }} \underline{ \text { }} \underline{ \text { }} \underline{ \text { }} \underline{ \text { }} \underline{ \text { }} \\\text { mystery }(3,2) & \underline{ \text { }} \underline{ \text { }} \underline{ \text { }} \underline{ \text { }} \underline{ \text { }} \underline{ \text { }}\\\text { mystery }(16,5) & \underline{ \text { }} \underline{ \text { }} \underline{ \text { }} \underline{ \text { }} \underline{ \text { }} \underline{ \text { }}\\\text { mystery }(80,9) & \underline{ \text { }} \underline{ \text { }} \underline{ \text { }} \underline{ \text { }} \underline{ \text { }} \underline{ \text { }} \\\text { mystery }(1600,40) & \underline{ \text { }} \underline{ \text { }} \underline{ \text { }} \underline{ \text { }} \underline{ \text { }} \underline{ \text { }} \end{array}
Unlock Deck
Unlock for access to all 8 flashcards in this deck.
Unlock Deck
k this deck
8
Assertions
For the following method, identify each of the three assertions in the table below as being either ALWAYS true, NEVER true or SOMETIMES true / sometimes false at each labeled point in the code. (You may abbreviate these choices as A/N/S respectively.)
public static int mystery(int x) {
int y = 1;
int z = 0;
// Point A
while (y <= x) {
// Point B
y = y * 10;
z++;
// Point C
}
// Point D
z--;
// Point E
return z;
}
y>xz<0z>0 Point A  Point B  Point C  Point D  Point E \begin{array}{|c|c|c|c|} \hline& \mathrm{y}>\mathrm{x} & z<0 & z>0 \\\hline \text { Point A } & & & \\\hline \text { Point B } & & & \\\hline \text { Point C } & & & \\\hline \text { Point D } & & & \\\hline \text { Point E } & & & \\\hline\end{array}
Unlock Deck
Unlock for access to all 8 flashcards in this deck.
Unlock Deck
k this deck
locked card icon
Unlock Deck
Unlock for access to all 8 flashcards in this deck.