This week's book giveaway is in the Design forum.
We're giving away four copies of Design for the Mind and have Victor S. Yocco on-line!
See this thread for details.
Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Need help with Assignment Java-2 (EvenOrOdd).

 
P. Larson
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 48652
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for the help and for the link!! I now know that the code is working fine now.
 
Campbell Ritchie
Sheriff
Posts: 48652
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well done
 
fred rosenberger
lowercase baba
Bartender
Pie
Posts: 12097
30
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Greg Charles
Sheriff
Posts: 2985
12
Firefox Browser IntelliJ IDE Java Mac Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 48652
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But you will have to get the code all polished if you are undergoing nitpicking.

I shall move this discussion there.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic