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.
Wink, wink, nudge, nudge, say no more ... https://richsoil.com/cards

All times above are in ranch (not your local) time.
The current ranch time is
Oct 22, 2017 15:39:49.