jQuery in Action, 2nd edition
The moose likes Beginning Java and the fly likes Listing even and odd numbers Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "Listing even and odd numbers" Watch "Listing even and odd numbers" New topic
Author

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) {


system.out.println(i);
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.


Thanks,
Mathews
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: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: Listing even and odd numbers
 
Similar Threads
Reg Operators
Regarding assertion
Javascript: SELECT Object?
"assert i%2==0 : i--;"question required
continue statement...