Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

Check odd or even

  Asked By: Ronnie    Date: Jan 14    Category: Java    Views: 2685

I wonder is it possible to write a java code that
checks wether a number is odd or even just like that?
I desperately need it.



1 Answer Found

Answer #1    Answered By: Raul Clark     Answered On: Jan 14

Try the following pice of code:

public class Tester {

public static boolean isOdd(int number){
if (number % 2 == 0)
return false;
return true;

public static void main(String[] args) {
for (int i = 0; i < 100;i++)
if (isOdd(i))
System.out.println (i + ": Odd");
System.out.println (i + ": Even");

Didn't find what you were looking for? Find more on Check odd or even Or get search suggestion and latest updates.