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;
> 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
~
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);