hi guys, i need help!, how do i extract odd digits from a positive number, example: 1234567 then only 1357 will be extracted out from the value 1234567? I noe can make use of modules % to check for odd and even number however i do not know how to extract the odd value out 1 by 1 from a set of value

Recommended Answers

All 4 Replies

You can convert the number to a String then extract every char that is one of '1', '3' etc from that String.

You can convert the number to a String then extract every char that is one of '1', '3' etc from that String.

ohh!, how do i do tat?

Is this homework? I've pointed you in the right direction, now you have to do some work.

To convert an integer to a String:

int x = 1234567;
String str = "" + x;

Look up charAt in String class documentation for extracting individual characters from a string.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.