
-----------------------------------
uberwalla
Thu Feb 21, 2008 4:41 pm

Use only a certain digit in a number
-----------------------------------
hey there quick question. This say i am given a number "12345", how would i go about just getting one digit out of that? so that i could pull all the numbers out and go 1+2+3+4+5+6 and stuff like that

-----------------------------------
HeavenAgain
Thu Feb 21, 2008 4:48 pm

RE:Use only a certain digit in a number
-----------------------------------
if its a string, then its fairly easy
for (int i = 0 ; i < number.length(); i++)
  sum += Character.getNumericValue(number.charAt(i));
if its not a string, then you can just go
while (temp>0){
 digit = temp%10;
 temp /= 10;
}

-----------------------------------
OneOffDriveByPoster
Thu Feb 21, 2008 4:53 pm

Re: Use only a certain digit in a number
-----------------------------------
hey there quick question. This say i am given a number "12345", how would i go about just getting one digit out of that? so that i could pull all the numbers out and go 1+2+3+4+5+6 and stuff like thatThe % operator gives you the remainder after division with /.  Remember that 12345 = 1 * 10000 + 2 * 1000 + 3 * 100 + 4 * 10 + 5 * 1.

-----------------------------------
uberwalla
Thu Feb 21, 2008 5:27 pm

Re: Use only a certain digit in a number
-----------------------------------
works pretty well thanks guys
