Forums Register Login
Listing even and odd numbers
I am trying to write a program that when prompted ask the user to enter a number greater than 10 and lists all the even or odd numbers. I used this code for the even list in a switch statement.
int i ;

System.out.println("The even numbers are");

for(i = 0; i < nnum;i++)

{ i = i + 1;
if (nnum %2 == 0) {

When i compliled it I inputted 10 and only got 0 . What am I doing wrong?
Nothing. Just Conmment the increment inside the for loop you will get all the even numbers.
You said the program asks the user to enter a number " > " 10, yet you entered 10 :? Are you trying to test your program for mischievous users? It also seems like you want to take a number and get all of the even integers up to that number and all the odd integers up to that number. Is that what you are looking for? Please let me try an example, and see if it helps you.
It's hard to fight evil. The little things, like a nice sandwich, really helps. Right tiny ad?
Rocket Oven Kickstarter - from the trailboss

This thread has been viewed 862 times.

All times above are in ranch (not your local) time.
The current ranch time is
Jul 23, 2018 04:06:12.