Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 9 of 9

Thread: Odious number

  1. #1
    Junior Member
    Join Date
    Mar 2012
    Location
    Dhaka,bangladesh
    Posts
    7
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default Odious number

    hello everyone..i need help with this problem to determine a number whether its odious number or not.. im wondering how to convert a given number to its binary value.. any idea? thanks..
    Last edited by ahanf; July 31st, 2012 at 03:05 PM.


  2. #2
    Forum VIP
    Join Date
    Oct 2010
    Posts
    275
    My Mood
    Cool
    Thanks
    32
    Thanked 54 Times in 47 Posts
    Blog Entries
    2

    Default Re: Odious number

    Consider reading the API for what you are attempting to do before requesting help on a public forum.

    Integer (Java Platform SE 6)

    Short psuedocode
    public static boolean isOdius(int num)
    {
      binary is the binary representation of the number
     
      counter is 0
      for each number in binary
      {
         if number equals 1
           counter is counter plus one
      }
      return if counter is odd
    }
    Last edited by Tjstretch; July 31st, 2012 at 03:09 PM. Reason: fail

  3. The Following User Says Thank You to Tjstretch For This Useful Post:

    ahanf (August 1st, 2012)

  4. #3
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Odious number

    how to convert a given number to its binary value.
    What format is the number stored in? String or int or ?
    What format should the converted number be in?
    See the Integer class for useful methods for doing conversions from one format to another.
    If you don't understand my answer, don't ignore it, ask a question.

  5. The Following User Says Thank You to Norm For This Useful Post:

    ahanf (August 1st, 2012)

  6. #4
    Member
    Join Date
    Feb 2012
    Posts
    173
    Thanks
    6
    Thanked 10 Times in 10 Posts

    Default Re: Odious number

    String bin = Integer.to______String(12345);
    Integer binNum =  Integer.________(___);

    Fill in the blanks, if you need to make the binary number beyond Integer.MAX_VALUE, then use a Long, and if you still need more room, use a BigInteger.

  7. #5
    Junior Member
    Join Date
    Mar 2012
    Location
    Dhaka,bangladesh
    Posts
    7
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default Re: Odious number

    Quote Originally Posted by Norm View Post
    What format is the number stored in? String or int or ?
    What format should the converted number be in?
    See the Integer class for useful methods for doing conversions from one format to another.
    ^int value i guess..here's the question..
    In odious number is a nonnegative number that has an odd number of 1s in its binary expansion. The first few odious numbers are therefore 1, 2, 4, 7, 8, 11, 13, 14, 16, 19, ... (Sloane's A000069). Numbers that are not odious are said to be evil numbers.

    Determine if a given number is Odious or Evil number..

    btw..thanks for the help guys.. seems like i should have check javadoc first..too easy..
    Last edited by ahanf; August 1st, 2012 at 03:14 AM.

  8. #6
    Member
    Join Date
    Jun 2012
    Posts
    41
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default Re: Odious number

    Learning to read javadocs is a very important skill I've found.

    aesguitar, what's BigInteger? I've heard of it, but I've never actually looked into it. Please tell me more.

  9. #7
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 263 Times in 232 Posts

    Default Re: Odious number

    Quote Originally Posted by lightOfDay View Post
    Learning to read javadocs is a very important skill I've found.

    aesguitar, what's BigInteger? I've heard of it, but I've never actually looked into it. Please tell me more.
    It is a big integer. Your favorite search engine is a better place to ask that question. Too much information is available already without the cost of volunteer's time.

  10. #8
    Member
    Join Date
    Jun 2012
    Posts
    41
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default Re: Odious number

    Jeez, sorry...

  11. #9
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 263 Times in 232 Posts

    Default Re: Odious number

    Quote Originally Posted by lightOfDay View Post
    Jeez, sorry...
    I apologize if that come across rude. I did not mean it rude. Just pointing you in the right direction.

Similar Threads

  1. How To Ask the User to Enter Another Number Using the Number 1
    By Pettsa in forum Object Oriented Programming
    Replies: 6
    Last Post: May 3rd, 2012, 03:44 AM
  2. Random number
    By Imran Ahmad in forum Java Theory & Questions
    Replies: 1
    Last Post: April 30th, 2012, 11:53 AM
  3. How to returned random number to original number?
    By i4ba1 in forum Algorithms & Recursion
    Replies: 2
    Last Post: March 19th, 2011, 04:35 AM
  4. HELP. Random Number Between
    By Raymond Pittman in forum Java Theory & Questions
    Replies: 3
    Last Post: February 15th, 2011, 09:50 AM
  5. Help With Odd/Even number program
    By JonoScho in forum What's Wrong With My Code?
    Replies: 7
    Last Post: November 23rd, 2009, 10:53 AM