i'm trying find way increase value using charat, want able update while inside while loop. below current code have. have tried recreating variable inside of loop , adding ++ end increase value, receive unexpected type errors.
i trying have take value enter (i.e. 3124) , concatenate each value , add them together. based on example, give value of 10.
public static void main(string[] args) { int num, counter, i; string str1; str1 = joptionpane.showinputdialog("enter number: "); num = str1.length(); counter = 0; = integer.parseint(character.tostring(str1.charat(0))); numtot = 0; while (counter <= num) { numtot = i; counter++; = integer.parseint(character.tostring(str1.charat(0++))); } system.exit(0); }
some modifications program :
public static void main (string[] args) throws java.lang.exception { int num, counter, i; string str1; int numtot = 0; str1 = "3124"; num = str1.length(); counter = 0; while (counter < num) { = integer.parseint(character.tostring(str1.charat(counter))); numtot = numtot + i; counter++; } system.out.println(numtot); }
Comments
Post a Comment