4 Replies - 902 Views - Last Post: 22 July 2012 - 05:04 PM Rate Topic: -----

#1 rjohn5854  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • 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  Icon User is offline

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

Reputation: 8325
  • View blog
  • Posts: 31,857
  • 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 ?
Was This Post Helpful? 3
  • +
  • -

#3 rjohn5854  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • 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 :D
Was This Post Helpful? 0
  • +
  • -

#4 CasiOo  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 1379
  • Posts: 3,039
  • 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 :)
Was This Post Helpful? 0
  • +
  • -

#5 rjohn5854  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • 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. :bananaman:
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1