• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Need help with Assignment Java-2 (EvenOrOdd).

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.



 
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well done
 
lowercase baba
Posts: 13089
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 3063
12
Mac IntelliJ IDE Python VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic