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


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » This Site » Cattle Drive
Bookmark "Need help with Assignment Java-2 (EvenOrOdd). " Watch "Need help with Assignment Java-2 (EvenOrOdd). " New topic
Author

Need help with Assignment Java-2 (EvenOrOdd).

P. Larson
Greenhorn

Joined: Sep 21, 2013
Posts: 8
I'm trying to complete my java assignment Java- 2 (Even Or Odd ). But I don't know if I'm even writing the code right at all. Every time that I run my code it print out even without typing anything. I'm just making sure that I'm doing everything right, so that I can move on to the next assignment. Thank you for your help!! Here is what the assignment says :
Write a program that will read in a number from the command line and tell me if it is even or odd. In other words, I want to type java EvenOrOdd 28 and see even.


Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 40030
    
  28
You are always passing the number 28, so it will always think it is even. You can pass
java MyEvenOrOdd 123
before you run the program. In that wase you would expect "123" to be args[0], and you will suffer en Exception if you try to pass 1.234 or if you miss out the number. You can read more about the command line in the Java Tutorials (I/O section).
P. Larson
Greenhorn

Joined: Sep 21, 2013
Posts: 8
Thank you for the help and for the link!! I now know that the code is working fine now.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 40030
    
  28
Well done
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11495
    
  16

Just a general note - we really like it if you tell us where you get your problems. It's really only polite to the owner. Plus, if it is from something like a web site, it allows us to check that you have copied it correctly.


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Greg Charles
Sheriff

Joined: Oct 01, 2001
Posts: 2864
    
  11

It's actually a problem from our very own Cattle Drive.

P. Larson, we have a forum just for the Cattle Drive. You're welcome to post there too.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 40030
    
  28
But you will have to get the code all polished if you are undergoing nitpicking.

I shall move this discussion there.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Need help with Assignment Java-2 (EvenOrOdd).