• Post Reply Bookmark Topic Watch Topic
  • New Topic

need help figuring out what is wrong with this code  RSS feed

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
this is the question. write a program that will display all the odd number between 1 and 15. here is the code that i use


tell me what is wrong because I am not getting what the questions say.

 
Rancher
Posts: 1090
14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi and Welcome.

Is that all of the code you have written? Or is there more to it? Like a method? And a class?

Let us know so we can guide and help you.
 
Chan Ag
Rancher
Posts: 1090
14
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
luana taylor wrote:write a program that will display all the odd number between 1 and 15.
...................

I am not getting what the questions say.



The question is asking you to display the odd numbers between 1 and 15 on your display. So your program could do the following or similar.

1. Pick the first number.
2. Check if it is an odd number.
3. Print it if is odd. Ignore this number otherwise.
4. Pick the next number. Check if is not exceeding the upper limit (15). If it is within the range, repeat 1-4. Else stop.



 
Ranch Hand
Posts: 89
C++ Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tell me what's the purpose of the for loop?
As it is..the for loop is accepting 15 numbers from the user.
The 15th number that the user accepts is checked if it is odd or not.
I would suggest something like:

 
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
luana taylor wrote:this is the question. write a program that will display all the odd number between 1 and 15. here is the code that i use

Are those your exact instructions? - "Write a program that will display all the odd number between 1 and 15".

If so, why have you defined a Scanner? Scanners are for input, not display.

Winston

PS: Welcome to JavaRanch, luana.
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i guess what he meant is when he type in the 15 odd number then display out ?
 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
voice ice wrote:i guess what he meant is when he type in the 15 odd number then display out ?

Possibly, but the problem is: we don't know.

And welcome to JavaRanch too, voice.

Winston
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!