Question

In: Computer Science

What will the following code segments print on the screen? int num = 3; switch (num){...

What will the following code segments print on the screen?

int num = 3;

switch (num){

            case 1:

                        System.out.println(“Spring”);

case 2:

                        System.out.println(“Summer”);

case 3:

                        System.out.println(“Autumn”);

case 4:

                        System.out.println(“Winter”);

}

Solutions

Expert Solution

Thanks for the question

===================================================================

The code will output

Autumn

Winter

Since we are not using break statement, in Case 3 , the cases below Case 3 will also get executed.

Here is the output screenshot when you run it -

If we use break statement like below it will only print Autumn


Related Solutions

Q1: Given the following code, what is returned by tq(4)? int tq(int num){ if (num ==...
Q1: Given the following code, what is returned by tq(4)? int tq(int num){ if (num == 0) return 0; else if (num > 100) return -1; else     return num + tq( num – 1 ); } Group of answer choices: 0 4 -1 10 Q2: Given that values is of type LLNode<Integer> and references a linked list (non-empty) of Integer objects, what does the following code do if invoked as mystery(values)? int mystery(LLNode<Integer> list) {    if (list.getLink() ==...
5C++ Questions 1. What will the following code print? num = 8; cout << --num <<...
5C++ Questions 1. What will the following code print? num = 8; cout << --num << " "; cout << num++ << " "; cout << num; 2.Since the while loop evaluates the condition before executing the statement(s), it is known as a(n)____ loop, whereas the do-while loop evaluates the condition after the statements have been executed, it is known as a(n)____ loop. 3.T/F While loops can only be used when a counter is decremented to zero. If the counter...
What is the ouput of the following code? void loop(int num) { for(int i = 1;...
What is the ouput of the following code? void loop(int num) { for(int i = 1; i < num; ++i) { for(int j = 0; j < 5; ++j) { cout << j; } } } int main() { loop(3); return 0; }
(True or False) The following function will compile. void print(int num) { return num+1; } Group...
(True or False) The following function will compile. void print(int num) { return num+1; } Group of answer choices True False Flag this Question Question 2 10 pts (True or False) The following code will output "I was true". bool isGreater(string s1, string s2) { if(s1 > s2) { return true; } return false; } int main() { if(isGreater("before","back")) { cout << "I was true"; } else { cout << "I was false"; } return 0; } Group of answer...
What output is produced by the following code fragment? int num = 0, max = 20;...
What output is produced by the following code fragment? int num = 0, max = 20; while (num < max) { System.out.println(num); num += 4; }
Viewing the code snippet below answer the following questions: int num=10; do {      cout << “Hello”...
Viewing the code snippet below answer the following questions: int num=10; do {      cout << “Hello” << endl;      num--; } while(num > 1); After the above code is executed: “Hello” printed how many times: ___________ What is value ofnum:  ____________ language is c++
1)What is the output of the following code? struct someType { int a; int b; };...
1)What is the output of the following code? struct someType { int a; int b; }; void f1(someType &s) { s.a = 1; s.b = 2; } someType f2(someType s) { someType t; t = s; s.a = 3; return t; } int main() { someType s1, s2; f1(s1); s2 = f2(s1); cout << s1.a << '-' << s1.b << '-' << s2.a << '-' << s2.b << '-' << endl; return 0; } ------------------------------------------------------------------------------------------------------------------ 2) struct dateType { int...
consider execution of the following switch statement: int Enter = 10; cin >> Enter; switch (Enter)...
consider execution of the following switch statement: int Enter = 10; cin >> Enter; switch (Enter) { case 1: Enter = -4; case 2: Enter = -6; case 4: break; case 6: Enter = -8; break; default: Enter = -1; } What would the value of Enter be after execution of this code if the value read for Enter were 4? -4,-6,-8 or none
What is the output of the following C++ code? int* length; int* width; length = new...
What is the output of the following C++ code? int* length; int* width; length = new int; *length = 5; width = length; length = new int; *length = 2 * (*width); cout << *length << " " << *width << " " << (*length) * (*width) << endl;
3. Translate the following C code to MIPS assembly code (in two separate files). int main()...
3. Translate the following C code to MIPS assembly code (in two separate files). int main() { printf(“before subroutine!\n”); Subfunc(); printf(“after subroutine!\n!”); } void Subfunc() {printf(“I am subroutine!\n”);} Submission file: Lab4_3a.asm for the main routine and Lab4_3b.asm for the sub-routine.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT