PART 1. EXAMINE THE FF. CODE   int numValue =2; int answer =0; switch(numValue){ case 1: answer +=1; case 2: answer +=2; case 3: answer +=3;             break; case 4: answer +=4; case 5: answer +=5; default: answer =0;             break; } cout <<”Answer: ” << answer << endl;   1. What is the answer(output) if the value of numValue is 2

EBK JAVA PROGRAMMING
9th Edition
ISBN:9781337671385
Author:FARRELL
Publisher:FARRELL
Chapter4: More Object Concepts
Section: Chapter Questions
Problem 9RQ
icon
Related questions
Question

PART 1. EXAMINE THE FF. CODE

 

int numValue =2;

int answer =0;

switch(numValue){

case 1: answer +=1;

case 2: answer +=2;

case 3: answer +=3;

            break;

case 4: answer +=4;

case 5: answer +=5;

default: answer =0;

            break;

} cout <<”Answer: ” << answer << endl;

 

1. What is the answer(output) if the value of numValue is 22? ____________________

2. What is the answer(output)  if the value of numValue is 1? ____________________

3. What is the answer(output)  if the value of numValue is 4? ____________________

4. What is the answer(output)  if the value of numValue is 2? ____________________

5. Is break statement in the default case needed?  Why or why not? Explain.____________________

 

Expert Solution
steps

Step by step

Solved in 4 steps

Blurred answer
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT