By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,119 Members | 2,064 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,119 IT Pros & Developers. It's quick & easy.

Program the displays even numbers only!!

P: 34
I ned help in figuring out to make my program display even numbers only. My for loop counts every number, but I only need to display the even ones. Can someone help me with this?
Feb 15 '07 #1
Share this Question
Share on Google+
4 Replies


P: 34
I figured it out no need to respond to the above message!

Thanks
Feb 15 '07 #2

Ganon11
Expert 2.5K+
P: 3,652
Glad to see you got it working. Out of curiosity, what method did you implement?
Feb 16 '07 #3

P: 34
What I did was
int [] numbers = {0,2,3,4,6,8....};
for (int item : numbers)
was suppose to do I misread the instructions.
Feb 16 '07 #4

10K+
P: 13,264
What I did was
int [] numbers = {0,2,3,4,6,8....};
for (int item : numbers)
was suppose to do I misread the instructions.

Expand|Select|Wrap|Line Numbers
  1.  int [] numbers = {0,2,3,4,6,8....};
will not compile.

You should have used aloop instead that counts to the largets number you want and tested for even using the % operator.
Feb 17 '07 #5

Post your reply

Sign in to post your reply or Sign up for a free account.