I don’t want to think Jun 13, 2019 There are days where I simply don’t want to think. I don’t want to have to think about anything. Is that wrong? I’m not sure. Is that okay? Nope, still not sure. It would be nice to be able to figure out everything that occurs in this life and yet here we all are, hoping something will happen. yet we simply don’t know or fully understand what will happen or when that will occur. So that’s life right now. Just deal with it I suppose.
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