Write a program that displays even numbers from 1 to 100 separated by spaces or each on a new line. Use “for” loop. for(int i=1;i<100;i++) System.out.println(i); I dont know why its not working.

asked 03 Mar '15, 19:19

Mohsin%20Ahmed%20Siddiqui's gravatar image

Mohsin Ahmed...
11
accept rate: 0%


Your code dilspays all numbers from 1 to 99, but in the task it said to display only even numbers

link

answered 03 Mar '15, 19:26

yulsonn's gravatar image

yulsonn
261
accept rate: 100%

I just forgot to see the word even.Thanks

link

answered 03 Mar '15, 19:31

Mohsin%20Ahmed%20Siddiqui's gravatar image

Mohsin Ahmed...
11
accept rate: 0%

Even numbers. For check number for even you can use operator %.

link

answered 04 Mar '15, 04:46

RabenokDmitry's gravatar image

RabenokDmitry
1263
accept rate: 14%

\try this buddy: for(int i=2;i<=100;i+2) { System.out.println(i); }

link

answered 05 Mar '15, 17:18

AristocratSudip's gravatar image

AristocratSudip
162
accept rate: 4%

correct loop: for (int i = 2; i <= 100; i+=2)

(05 Mar '15, 18:42) Elleonora Carry ♦♦

this will print the value of i not the text given in the task.

link

answered 07 Mar '15, 19:40

Mohsin%20Ahmed%20Siddiqui's gravatar image

Mohsin Ahmed...
11
accept rate: 0%

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "Title")
  • image?![alt text](/path/img.jpg "Title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Tags:

×15

Asked: 03 Mar '15, 19:19

Seen: 1,505 times

Last updated: 07 Mar '15, 19:40