Parsing through text field

I would like to parse through a text field which is actuall a number and add the numbers as i go through it.

I already have the code to ensure that it is number/integer. But now I need to parse through it and add as I go.

Example

string a;

int d = 0;

a= ("143");

for loop of some kind

//first time through

d = d + 1

//second time

d = d +4

//third time

d = d + 3

//Break loop

d == 8;

[473 byte] By [archer9113a] at [2007-11-27 0:29:17]
# 1
for each characterparse the character as a numberadd it to the totalOr for positive numbers...while the int value is greater than 0add the value of the 'ones' column to the totaldivide the int value by 10~
yawmarka at 2007-7-11 22:31:32 > top of Java-index,Java Essentials,Java Programming...
# 2
that is what I am trying to docan you supply syntaxTIAsteve
archer9113a at 2007-7-11 22:31:32 > top of Java-index,Java Essentials,Java Programming...
# 3
I am doing a chcek to ensure positive numbers only
archer9113a at 2007-7-11 22:31:32 > top of Java-index,Java Essentials,Java Programming...
# 4

> can you supply syntax

Can you give it a shot, first? You'll want to look up the % operator to get the values in the ones column. I assume you know how to divide a number and save that value in a variable.

http://java.sun.com/docs/books/tutorial/java/nutsandbolts/operators.html

~

yawmarka at 2007-7-11 22:31:32 > top of Java-index,Java Essentials,Java Programming...
# 5

Close but still not working correctly

int d = 123;

int dq = 1 ;

int results = 0;

int count = 0;

while (dq > 0)

{

dq = d % (d/10);

results = results + dq;

count = count + 1;

JOptionPane.showMessageDialog(frame,"ADDING" + results + " %= " + dq +" count = " + count + " d= " + d);

d = d/10;

}

JOptionPane.showMessageDialog(frame,"ENTERING PROCESS AREA." + dq + " - results - " + results);

archer9113a at 2007-7-11 22:31:32 > top of Java-index,Java Essentials,Java Programming...
# 6

String s = "143";

int i = Integer.parseInt(s);

int total = 0;

while (i > 0) {

total += i % 10;

i /= 10;

}

System.out.println(total);

~

yawmarka at 2007-7-11 22:31:32 > top of Java-index,Java Essentials,Java Programming...
# 7
Thanks - I was getting there (a messy way)thanks againsteve
archer9113a at 2007-7-11 22:31:32 > top of Java-index,Java Essentials,Java Programming...