Logo 
Search:

Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

Check odd or even

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

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.

Share: 

 

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");
else
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.




Tagged: