SCJP 1.4, SCWCD 1.4 - Hints for you, Certified Scrum Master
Did a rm -R / to find out that I lost my entire Linux installation!
Sergej Smoljanov wrote:
ps. question like this claim maximum attention and time (my own opinion)
Prathima gaitonde wrote:I need your advise, any simple tip to solve complex looping in quick time.
so last condition is 11
Sergej Smoljanov wrote:you use post increment so last condition is 11
1 234 567 8910 11
1+2+4+5+7+8+10+11=48
Roel De Nijs wrote:
Sergej Smoljanov wrote:you use post increment so last condition is 11
1 234 567 8910 11
1+2+4+5+7+8+10+11=48
I have to nitpick a little bit, as this isn't 100% correct. The iteration with count = 0 is missing, although this won't affect the result in the end (0 + 0 = 0 ). And the final value of count will be 12 (also not important for the result, but could be if count was printed as well).
If you had a few small print statements to the code, you can actually see what's going on. This code snippet
produces the following output:
c: 0 c: 1 -> s: 1
c: 2 -> s: 3
c: 3 c: 4 -> s: 7
c: 5 -> s: 12
c: 6 c: 7 -> s: 19
c: 8 -> s: 27
c: 9 c: 10 -> s: 37
c: 11 -> s: 48
The end! c: 12 s: 48
Hope it helps!
Kind regards,
Roel
Sergej Smoljanov wrote:you are right. First i think that make mistake in checking last expression, but now see that i overlook first checking and this also important for exam. for example this one
can be overlooked also.
Daniel Andres wrote:
Sergej Smoljanov wrote:you are right. First i think that make mistake in checking last expression, but now see that i overlook first checking and this also important for exam. for example this one
can be overlooked also.
What is the answer here
The end! c: 10 s: 10 ?
Daniel Andres wrote:Count starts at 0, so 0 divided by 3 is 0 which satisfies the reminder of == 0. What does this continue mean? If the statement evaluates to true then we do not add sum + count?
I see, for instance, that when count is 3 the statement evaluates to true as well, so the continue again means that the code ignores the rest of the if statement and skips to to while loop?
Daniel Andres wrote:What is the answer here
The end! c: 10 s: 10 ?
Did you see how Paul cut 87% off of his electric heat bill with 82 watts of micro heaters? |