Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
The moose likes Java in General and the fly likes boolean Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "boolean" Watch "boolean" New topic
Author

boolean

Tshepiso Mokgosi
Greenhorn

Joined: May 18, 2010
Posts: 1
How to check an odd number which is divisible by 3 and returns true
pete stein
Bartender

Joined: Feb 23, 2007
Posts: 1561
First and foremost -- welcome to JavaRanch!

Next off, I'm not sure exactly what it is that you're asking -- to check if the number is odd? that it's divisible by three? both?
Next, after clarifying your question, what have you tried so far, and how doesn't it work to your satisfaction?

And finally, I'm going to ask that the mods move this thread to the beginning Java section as it's not a Swing question.

Much luck, and again, welcome!
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19649
    
  18

Please UseAMeaningfulSubjectLine. You can use the edit button to change it in your original post.

Check out the % operator. For any multiple X of Y (for any values of X and Y), X % Y returns 0. I'm sure you can use that to check if a) your value is a divisible by 3, and b) your value is odd - not divisible by two.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
pete stein
Bartender

Joined: Feb 23, 2007
Posts: 1561
[psssst: or both at one shot -- if number mod 6 == 3]
 
 
subject: boolean