# How to separate numbers from a 3-digit integer.

Page 1 of 1

## 4 Replies - 1774 Views - Last Post: 22 July 2012 - 05:04 PMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=286621&amp;s=e40407ae72ec93b88c4d26fca74dcc77&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 rjohn5854

Reputation: 3
• Posts: 172
• Joined: 04-October 11

# How to separate numbers from a 3-digit integer.

Posted 22 July 2012 - 04:57 PM

How to separate values. For eg: User enters 435 - what would be the logic to extract & add the numbers like 4 + 3 + 5 = 12

The textbook gives a hint to use the modulus operator to extract the number. But, i really dont understand it.
Is This A Good Question/Topic? 0

## Replies To: How to separate numbers from a 3-digit integer.

### #2 pbl

• There is nothing you can't do with a JTable

Reputation: 8378
• Posts: 31,956
• Joined: 06-March 08

## Re: How to separate numbers from a 3-digit integer.

Posted 22 July 2012 - 04:59 PM

435 % 10 == 5
435 / 10 == 43
43 % 10 == 3
43 / 10 == 4
4 % 10 == 4

what else do you need ?

### #3 rjohn5854

Reputation: 3
• Posts: 172
• Joined: 04-October 11

## Re: How to separate numbers from a 3-digit integer.

Posted 22 July 2012 - 05:01 PM

Looks like that's all i need

### #4 CasiOo

• D.I.C Lover

Reputation: 1575
• Posts: 3,542
• Joined: 05-April 11

## Re: How to separate numbers from a 3-digit integer.

Posted 22 July 2012 - 05:03 PM

Modulus finds the remainder of division.

435 % 10 = 5
43 % 10 = 3
4 % 10 = 4

You will just need to divide by ten each step

### #5 rjohn5854

Reputation: 3
• Posts: 172
• Joined: 04-October 11

## Re: How to separate numbers from a 3-digit integer.

Posted 22 July 2012 - 05:04 PM

I suck at Math as simple as that haha. Thanks a lot.