Home > Back-end > About the topic of Java, bother everybody to help me take a look at the right
About the topic of Java, bother everybody to help me take a look at the right
Time:12-07
Please write a program to calculate the "1 + 3 + 5 + 7 +... + 99 "the value of the tip: 1) using a loop statements for natural number 1 ~ 99 traversal, 2), in the process of traverse through conditions determine whether the current traversal of the number is even, if it is the continue, or continue to perform,
Int sum=0; For (int I=1; i<=100; I++) { If (I % 2==0) { Sum=sum + I; continue; } System. The out. Println (sum); }
This code is written according to the above questions, just don't know where to write wrong, wrong operation result,
CodePudding user response:
How to run, you this calculation is the sum of an even number, to calculate the sum of an odd number of should be I % 2!=0; to