A for loop simplifies the counting, simplifies displaying text, and simplifies... the life of a programmer! And it saves a lot of time: just a couple of simple lines of code and you can display every even number from 1 to 100 inclusive. Let's try it, but be sure to put each value on a separate line.
Even numbers
- 2
Locked
Comments (14)
- Popular
- New
- Old
You must be signed in to leave a comment
ImDevin
2 April 2021, 01:55
is no one doing these tasks? no comment since May 20th 2020. I think I might keep posting these comments and see if anyone else writes anything :)
0
bob
21 May 2020, 01:30
for anyone who thinks that the seemingly particular word choice of "inclusive" would imply that we are to practice our "following particular details" duty and include 1 and 100, think again.
they only want the even numbers 2 to 100. See, your code was fine!
+5
raulGLD
19 October 2020, 09:15
God damn! I was looking fo this. Thank you! The word "inclusive" made me think the same way, so I added 1 and then all the even numbers.. this should really be changed. So for any new comers, just make sure you write all the even numbers from 1 to 100, WITHOUT 1 itself.
+4
Paul Harman
21 April 2020, 03:14
System.out.println("1");
for (int i = 2; i <= 100; i = i +2){
System.out.println(i);
+1
Paul Harman
21 April 2020, 03:13
I have 1 listed and then even numbers between 2 and 100 inclusive listed on screen but cannot satisfy third criteria.
+1
Paul Harman
21 April 2020, 03:14
System.out.println("1");
for (int i = 2; i <= 100; i = i +2){
System.out.println(i);
0
Paul Harman
21 April 2020, 03:23
removed the line to print 1, task is misleading in some will assume we are being asked to print 1 even though not even
0
Scott Böning
12 February 2020, 17:58
If you don't get output: you don't need to check whether the number is even. 1 isn't an even number, so it doesn't have to be displayed. The first number to be displayed is 2. So you just have to increment by two.
0
IO.Error
11 January 2020, 22:47
unable to get output
0
Glenn Meyer
29 October 2019, 01:52
Not sure why this is rated so low... did you guys skip the Pascal example page? :D This is a pretty straightforward for loop.
0
hidden #10527205
18 September 2019, 16:17
This seems to be a common issue. I am not getting any output too.
0
Laurence Chadwell
1 September 2019, 01:38
I solved this one, but the output window was not visible. @Roman
+1
Valeri Burlacu
5 July 2019, 15:58
I don't understand... what is the problem ? O_O
+1