Ask
your own question, for FREE!
Computer Science
13 Online
Wrte a for loop to compute the sum 1 + 2 + 3 + 4 Multiple answers. Answer A int sum =0; for (int j = 0 ; j < 4 ; j++) sum=sum+j; B int sum =0; for (int j = 1; j < 5 ; j++) sum=sum+j; C int sum =0; for (int j = 1 ; j < 6 ; j++) sum=sum+j; D int sum =0; for (int j = 1 ; j <= 4 ; j++) sum += j;
Still Need Help?
Join the QuestionCove community and study together with friends!
B
sum = 0 outside loop. ( initial value j=1; ending condition j<5; increment by 1 each round of lopp j++) sum = sum + j. so on round 1 sum=0+ 1 = 1 so on round 2 j= 2 not 1. so sum = 1 + 2 =3 (not 2 as is in the series needed) Is that a problem denyekwe?
d
B and D work
@arcticf0x why would you think D is wrong? it iterates 4 times because <=
Still Need Help?
Join the QuestionCove community and study together with friends!
Uh oh, overlooked, D is correct aswell. @Tomas.A
So B and D.
Can't find your answer?
Make a FREE account and ask your own questions, OR help others and earn volunteer hours!
Join our real-time social learning platform and learn together with your friends!
Join our real-time social learning platform and learn together with your friends!
Latest Questions
abby2blessed:
How do you guys feel about second chances? Concerning relationships, both romantic and otherwise.
TJH:
love Love, it comes, it goes But what if it stayed stayed in the silence the storm stayed when the world was loud for me it's different; it left when it was
Puffer:
General question what came first the chicken or the egg itu2019s a trick question
Bounty:
the world keeps moving fast and I'm stuck in a time lapse all I need is a minute
Bounty:
can I get so tips on how to start my journey into semi-realism art also on how to
Strawberryluna:
Read my poem. Im not for criticism its a poem I wrote after my breakup: Youu2019ll never understand the way you made me break, I hate that I still love you
Bounty:
first poem in a min- (tittle)? one moment i'm fine I smile till my face burns I laugh till I cant breath Then I cry I wonder where I went wrong I listen to
Twaylor:
3d printing a glider (for 150 pound 5'8 person - prolly should make it for up to
4 days ago
0 Replies
0 Medals
4 days ago
4 Replies
3 Medals
4 days ago
5 Replies
1 Medal
1 week ago
4 Replies
0 Medals
2 weeks ago
0 Replies
0 Medals
5 days ago
5 Replies
2 Medals
3 weeks ago
5 Replies
1 Medal
4 hours ago
6 Replies
0 Medals