Answer the question and write the explantion. Question 5 // IF answer is a, expl
ID: 3866775 • Letter: A
Question
Answer the question and write the explantion.
Question 5 // IF answer is a, explain why b is not the answer; if nswer is b, explain why a is not the correct answer; if both a and b is correct answer, explain why both a and b is corrct answer.
In the Quiz class, the foo method has the following API:
public static double foo( int i)
Assuming x is an integer value, and assuming the following statement having been executed:
Quiz q = new Quiz();
which method call(s) could be used?
double i = Quiz.foo( x );
System.out.println(“ Foo has returned the double value: “ + q.foo( x));
both a and b
neither a or b
Question 11
What are the values of i and sum after this code sequence is executed?
int i = 0;
int sum = 0;
for ( i = 0; i < = 40; i++)
{
if ( i % 10 = = 0)
sum += i ;
}
i is 40
sum is 60
i is 41
sum is 60
i is 40
sum is 100
i is 41
sum is 100
double i = Quiz.foo( x );
b.System.out.println(“ Foo has returned the double value: “ + q.foo( x));
c.both a and b
d.neither a or b
Question 11
What are the values of i and sum after this code sequence is executed?
int i = 0;
int sum = 0;
for ( i = 0; i < = 40; i++)
{
if ( i % 10 = = 0)
sum += i ;
}
a.i is 40
sum is 60
i is 41
sum is 60
i is 40
sum is 100
i is 41
sum is 100
Explanation / Answer
Question 5:
Answer:System.out.println(“ Foo has returned the double value: “ + q.foo( x));
not A because after creation of object for a class we should access through the object
Answer is B because the function call should be made using the objecct q
Question 11:
I=41 and sum =100
since While exiting the loop the value will be once incremented and the condition i<=40 failed and so exits the loop
and the sum of the numbers from 0 to 40 which exactly divided by 10 is 10+20+30+40=100
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.