Ask
your own question, for FREE!
Computer Science
18 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
playtsec:
how do I sleep without getting a sore throat? I always wake up with a sore throat but it goes away later in the day.
75:
how do you react when you deal with someone who plays the victim in every single situation, and do you find this behavior childish or annoying.
JohnnyLFowler0812:
Do you guys ever think that the homeless are going to be healthy and freed from h
JohnnyLFowler0812:
Do you guys ever think that Hikaru Nikanura will ever be take Magnus Calrsen's 1st place title in the wolrdin the United States amd Norway? Right now Hikaru
DoltonCarlee:
what are y'all's options on S A T essays because honestly their not that bad
thereneelg:
Can someone give me a summary of article 231, The war guilt clause?? I need to explain what it is, but I can't find any shortened version of what it is and
luisaam2:
What should you do when the person you want to talk to the most is the one making
2 hours ago
9 Replies
2 Medals
34 minutes ago
3 Replies
0 Medals
8 hours ago
7 Replies
1 Medal
12 hours ago
2 Replies
0 Medals
12 hours ago
7 Replies
2 Medals
3 days ago
7 Replies
1 Medal
2 days ago
16 Replies
1 Medal