Consider the following code segments: public static void main(String[] args) {..
ID: 3804331 • Letter: C
Question
Consider the following code segments:
public static void main(String[] args) {.........................(1)
int enigma = 12;...............................................(2)
int mystery = 15;..............................................(3)
int riddle = 30;...............................................(4)
while(riddle>mystery) {........................................(5)
int result = myMethod(mystery, riddle);......................(6)
System.out.println(result); ..................................(7)
riddle--; ....................................................(8)
mystery++; ...................................................(9)
private static int myMethod(int enigma, int mystery) {...........(13)
int riddle = enigma * mystery;.................................(14)
return riddle;.................................................(15)
What are the line numbers of the lines that are in the scope of the variable result declared at line 6?
What are the line numbers of the lines that are in the scope of the variable riddle declared at line 4?
What are the line numbers of the lines that are in the scope of the variable riddle declared at line 14?
What are the line numbers of the lines that are in the scope of the variable enigma declared at line 2?
Explanation / Answer
What are the line numbers of the lines that are in the scope of the variable result declared at line 6?
The scope of variable is with in the block as we all know, from line 6 to line 9 (both included).
What are the line numbers of the lines that are in the scope of the variable riddle declared at line 4?
Same goes with this, the scope of the variable riddle is within the block/method starting from line 4 to line 11 (both inclusive)
What are the line numbers of the lines that are in the scope of the variable riddle declared at line 14?
the scope of the variable riddle is within the block/method starting from line 14 to line 15 (both inclusive)
What are the line numbers of the lines that are in the scope of the variable enigma declared at line 2?
Same goes with this, the scope of variable riddle is within the block/method starting from line 2 to line 11 (both inclusive)
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.