fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static void main (String[] args) throws java.lang.Exception
  11. {
  12. int Num, counter, i;
  13. String str1;
  14. int NumTot = 0;
  15.  
  16. str1 = "3124";
  17. Num = str1.length();
  18.  
  19. counter = 0;
  20. // i = Integer.parseInt(Character.toString(str1.charAt(0)));
  21.  
  22.  
  23. while (counter < Num)
  24. {
  25.  
  26.  
  27. i = Integer.parseInt(Character.toString(str1.charAt(counter)));
  28. NumTot = NumTot + i;
  29. counter++;
  30. }
  31.  
  32.  
  33.  
  34. System.out.println(NumTot);
  35. }
  36. }
Success #stdin #stdout 0.1s 320320KB
stdin
Standard input is empty
stdout
10