• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

boolean

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How to check an odd number which is divisible by 3 and returns true
 
Bartender
Posts: 1561
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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!
 
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
pete stein
Bartender
Posts: 1561
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
[psssst: or both at one shot -- if number mod 6 == 3]
 
reply
    Bookmark Topic Watch Topic
  • New Topic