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..
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.
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.
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
ahanf (August 1st, 2012)
What format is the number stored in? String or int or ?how to convert a given number to its binary value.
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.
ahanf (August 1st, 2012)
^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.
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.
Jeez, sorry...