I'm new to Java and had a question about summing together the digits of a single binary value in Java.
For example,
If the binary value has an even number of 1's, I would like to output the String "even" to another method. If there are an odd number of 1's, then I want to output the String value "odd".
Below is an example of my code:
String eoro;
String name = "1010101011";
int num = Integer.parseInt(name, 2);
System.out.println(num);
if(num % 2 == 0)
eoro = "even";
else
eoro = "odd";
System.out.println(eoro);
The output comes up as
683
odd
I'm not sure if Integer.parseInt(name, 2); is the correct way of doing this, but I am unaware of another way of summing the digits of a single String value.
Please do not be rude and thanks for any help you can provide!