Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

10. Which of the following is not a syntax error? A. Neglecting to initialize a

ID: 3910186 • Letter: 1

Question

10. Which of the following is not a syntax error? A. Neglecting to initialize a local variable in a method before it is usd. B. Using a single equals sign instead of a double equals sign in the co of an if statement. C. Placing a semicolon at the end of the first line of an if statement. D. Omitting the left and right parenthesis for the condition of an if 11. Local variables must be: A. Initialized when they are declared. B. Initialized before their values are used in an expression. D. Declared at the top of the method. A. val +3: C. Declared and initialized in two steps. by 3 12. Which of the following code segments does not increment val B. val val+; val-val+1; val val+1; C. c- 3; val val +(c3?2:3); D. All of the above increment val by 3. 13. Which of the following segments is a proper way to call the method read four times? A. double k; k 0.0 while Ck I4) readDataO; // end while B. int i; while ( i

Explanation / Answer

Question 10 -----
Answer is A -----

Because it is compulsory to initialize local variable before use..
But it is not a syntax....
........
syntax of IF statement is..
if(condition)
{

}
we can not modify this syntax..
If we trying to make any changes in IF statement Syntax error occurs..
also single equal to(=) is a initialization operator and double equal to (==) is
comparision operator And we can not use initialization operator for condition..

----------------------------------------------------------------------------------------------------------------

----------------------------------------------------------------------------------------------------------------


Question 11 ------
Answer B ---------

Because when the instance and class variables are used before initialization
then the default value of them is considered as 0..
But local variable is fussy about where you position the declaration for it..you must
place the initialization before use of variable in an expression..

----------------------------------------------------------------------------------------------------------------------

----------------------------------------------------------------------------------------------------------------------

Question 12 -----
Answer C --------

Because in A .. val is directly incremented by 3..
In B..val is incremented 3 times by 1 it means it is incremented by 3..

But In C ..
3 assigned to variable c
then
in if condition c==3 is becomes true and first value means 2 is added in val
So in C val is incremented by 2.

------------------------------------------------------------------------------------------------------------------

------------------------------------------------------------------------------------------------------------------

Question 13 -----
Answer is A -----

In option A
k is declared of double type and 0.0 value is assigned to it.
then while loop condition checked
while(0.0 != 4) true
then readData() method called first time.
and k becomes 1.0
while(1.0 != 4) true
then readData() method called second time.
and k becomes 2.0
while(2.0 != 4) true
then readData() method called third time.
and k becomes 3.0
while(3.0 != 4) true
then readData() method called fourth time.
and k becomes 4.0
while(4.0 != 4) false
And while loop execution terminated...
-----------
So method called 4 times..

Thank you...

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote