Answer to Question #175420 in Java | JSP | JSF for Lucy

Question #175420

I. Identify and correct the errors in each of the following sets of code: [6 marks] i.

while ( c <= 5 ) {

product *= c; ++c;


ii. if ( gender == 1 )


System.out.println( "Woman" );

else;

System.out.println( "Man" );


iii. What is wrong with the following while statement?

while ( z >= 0 )

sum += z;


D. Explain two (2) programming situations that will require the use of overloaded methods [5 marks]


1
Expert's answer
2021-03-28T14:36:56-0400

1 There is no closing curly brace.

while (c <= 5) {
    product *= c;
    ++c;
}

2 Semicolon after else.

if (gender == 1)
    System.out.println("Woman");
else
    System.out.println("Man");

3 If z is greater than or equal to 0, then the loop will become infinite.

while (z >= 0) {
    sum += z;
    z--;
}


D If you want the child method to have different behavior, when you need to implement an abstract method or an interface method.


Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog