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..
Printable View
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..
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
Code :
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 }
What format is the number stored in? String or int or ?Quote:
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.
^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..
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...