Tue Jan 7 19:39:37 MST 2020 Let’s talk about today than shall we? I’d like to think it would be a nice moment in time if we could simply get along with everything that happens in this life, yet I doubt it will. It’s a shame if you think about it. A real shame. But what are you going to do with any of it? No one knows exactly. So here we sit waiting for something better to come along, hoping for something to happen and allowing us to actually see what is real and what isn’t.
Sometimes you want to be able to check if a number is odd or even. Here's a simple method that will do just that.
public class OddOrEven {
public static void main(String[] args) {
int i = Integer.valueOf(args[0]);
System.out.println(oddOrEven(i));
}
public static String oddOrEven(int number) {
if (number %2 == 0) {
return "Even";
} else {
return "Odd";
}
}
}
Naturally you'll want to do some value checking for the number input at the command line. It could easily throw an InvalidNumberFormat exception. I think that's the exception that would be thrown.
Comments
Post a Comment