1 int startingValue; 2 int terminatingValue; 3 int stepValue; 4 5 for (int i - s
ID: 3701430 • Letter: 1
Question
1 int startingValue; 2 int terminatingValue; 3 int stepValue; 4 5 for (int i - startingvalue; i terminatingValue; i + stepValue) switch( i ) 7 8 9 10 case e: System.out.print( "Hello there, ") break; 12 case 1: 13 14 15 16 17 18 19 20 21 System.out.println( "What's up? "); break; case 2: System.out.println( "How are you doing? ); break; case 3: System.out.printin "Terrific. ): break; case 4 System.out.printin( "Beautiful day isn't it? "; 23 24 25 26 27 28 29 / end switch 30 end for break; System.out-printIn( "Yes it is. ") System-out.println( "See you later case 5: break; default: Question 19Explanation / Answer
The out put for the above programm is:
See you later.
See you later.
See you later.
what's up?
Explanation:
If you take the sequence of i values they are like...-5,-3,-1,1,3,5.....since starting value is -5 and it increments by step of 2. (-5+2=-3)....(-3+2=-1)..
But there is a condition in for loop that i should be less than or equal to terminatingValue (i<=1).
So for the above programm , the only valid values are -5,-3,-1,1
Note: Switch condition will execute the default case, when i value doesn't matches with any case number
For the i value =-5:
Since there is no case with -5, swich case will execute default case which prints See you later.
For the i value =-3:
Since there is no case with -3, swich case will execute default case which prints See you later.
For the i value =-1:
Since there is no case with -1, swich case will execute default case which prints See you later.
For the i value =1:
Since there exists a case with 1, So switch condition will execute case 1 which prints what's up?.
And the next value of i is 3 (1+2). But the condition is(i<=1). So the condition fails and the programm terminates.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.