File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Assignment Java-2 (EvenOrOdd)

 
Steve Jensen
Ranch Hand
Posts: 126
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I need to get user input from the command line, the user input being an integer value, and determine whether the number is even or odd.
How do i get user input from the command line?
I've tried the code below, it compiles, but won't run.
Steve got the push he needed, so the code has been removed to encourage future searchers to think harder (or search more). -ds
Any suggestions would be greatly appreciated. :roll:
[ November 27, 2002: Message edited by: Dirk Schreckmann ]
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What do you expect that code to do, exactly?
-Barry
 
Steve Jensen
Ranch Hand
Posts: 126
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Take in a command line argument, such as the number 5, and convert it to an integer?
So, how do i go about doing it?
 
Norm Miller
Ranch Hand
Posts: 56
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your code looks good as far as it goes. You don't do anything with the value you read in (unless you are running in a debugger). I added a line to demonstrate this.
Steve got the push he needed, so the code has been removed to encourage future searchers to think harder (or search more). -ds
When I ran the class with java EvenorOdd 34, it showed the 34.
Of course, you still need to test for odd or even and display that result.
[ November 27, 2002: Message edited by: Dirk Schreckmann ]
 
Steve Jensen
Ranch Hand
Posts: 126
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, below is my completed solution:-
Steve got the push he needed, so the code has been removed to encourage future searchers to think harder (or search more). -ds
Just one thing though. I used all the references which were suggested on the question page. Well, am i expected to memorise procedures such as converting from a string to an int?
[ November 27, 2002: Message edited by: Dirk Schreckmann ]
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you use them enough they will stick, but you
must know where to look for them.
Take another look at the "requirements-spec", you
do not have a correct program yet.
Also you previously said that your program does
not run. What do you mean by that?
And take a look at the Cattle Ranch Style guide
and try to conform to it.
Better still join up and get beaten up like the rest-of us!
-Barry
(How's I'm a doin', M?)
 
Marilyn de Queiroz
Sheriff
Posts: 9059
12
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Steve Jensen:
Just one thing though. I used all the references which were suggested on the question page. Well, am i expected to memorise procedures such as converting from a string to an int?

You don't need to memorize them. After you use them for a while you'll learn them without much effort. As long as you know where to look for the way to get something done, that's sufficient to start.

You can post snippets or pseudocode here, but please don't post your solution. If you post great code, you will be robbing others of an education.
 
Marilyn de Queiroz
Sheriff
Posts: 9059
12
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Barry Gaunt:
If you use them enough they will stick, but you must know where to look for them.


Sorry, Barry, I just skipped right over this sentence before I posted. You're absolutely correct.

Take another look at the "requirements-spec", you do not have a correct program yet.

Something should always be printed, either "even" or "odd".

Also you previously said that your program does not run. What do you mean by that?

Being a little more specific in the question helps people understand and answer more quickly and accurately.

And take a look at the Cattle Ranch Style guide and try to conform to it.

Formatting your code is definitely helpful if you want people to read it.

(How's I'm a doin', M?)

Pretty good, Barry.
 
Steve Jensen
Ranch Hand
Posts: 126
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Marilyn de Queiroz:

You don't need to memorize them. After you use them for a while you'll learn them without much effort. As long as you know where to look for the way to get something done, that's sufficient to start.

You can post snippets or pseudocode here, but please don't post your solution. If you post great code, you will be robbing others of an education.


Oops, sorry.
I'll only post snippets on here from now on, at best.
OK, my program doesn't say "even" or "odd", and I am deviating away from the req. spec, which isn't good, but the program does what it's supposed to, right, it's just the println messages which I have to change?
 
Marilyn de Queiroz
Sheriff
Posts: 9059
12
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you enter "2" and it prints "even", and you enter "3" and it prints "odd", then it does what it is supposed to do.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic