Win a copy of The Journey To Enterprise Agility this week in the Agile and Other Processes forum! And see the welcome thread for 20% off.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

Listing even and odd numbers  RSS feed

 
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Ranch Hand
Posts: 211
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nothing. Just Conmment the increment inside the for loop you will get all the even numbers.
 
Ranch Hand
Posts: 123
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!