File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes Listing even and odd numbers Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Listing even and odd numbers" Watch "Listing even and odd numbers" New topic

Listing even and odd numbers

Lisa Smith
Ranch Hand

Joined: Sep 24, 2002
Posts: 57
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?
Mathews P Srampikal
Ranch Hand

Joined: Nov 26, 2002
Posts: 211
Nothing. Just Conmment the increment inside the for loop you will get all the even numbers.

Thomas Whalen
Ranch Hand

Joined: Aug 26, 2001
Posts: 123
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.

if you don't know, then ask. if you do know, then share. love is knowledge.
I agree. Here's the link:
subject: Listing even and odd numbers
It's not a secret anymore!