aspose file tools*
The moose likes Cattle Drive and the fly likes Assignment Java-2 (EvenOrOdd) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » This Site » Cattle Drive
Bookmark "Assignment Java-2 (EvenOrOdd) " Watch "Assignment Java-2 (EvenOrOdd) " New topic
Author

Assignment Java-2 (EvenOrOdd)

Steve Jensen
Ranch Hand

Joined: Sep 23, 2002
Posts: 126
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 ]

John Bonham was stronger, but Keith Moon was faster.
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
What do you expect that code to do, exactly?
-Barry


Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
Steve Jensen
Ranch Hand

Joined: Sep 23, 2002
Posts: 126
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

Joined: May 21, 2002
Posts: 56
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

Joined: Sep 23, 2002
Posts: 126
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

Joined: Aug 03, 2002
Posts: 7729
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

Joined: Jul 22, 2000
Posts: 9043
    
  10
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.


JavaBeginnersFaq
"Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt
Marilyn de Queiroz
Sheriff

Joined: Jul 22, 2000
Posts: 9043
    
  10
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

Joined: Sep 23, 2002
Posts: 126
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

Joined: Jul 22, 2000
Posts: 9043
    
  10
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.
 
wood burning stoves
 
subject: Assignment Java-2 (EvenOrOdd)
 
Similar Threads
Change Program (How can I get two inputs)
user input
IO
Convert English word to arabic
How to use Cron job with Java program?