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. Scanner input = new Scanner(System.in);
  13. System.out.println("Please enter a string: ");
  14. String STR=input.next();
  15. int numberDigits=0;
  16. int length=STR.length();
  17. char c;
  18. for (int i=0; i<length; i++){
  19. c=STR.charAt(i);
  20. if (c==0){
  21. numberDigits++;
  22. }
  23. else if (c=='1'){
  24. numberDigits++;
  25. }
  26. else if(c=='2'){
  27. numberDigits++;
  28. }
  29. else if(c=='3'){
  30. numberDigits++;
  31. }
  32. else if(c=='4'){
  33. numberDigits++;
  34. }
  35. else if(c=='5'){
  36. numberDigits++;
  37. }
  38. else if(c=='6'){
  39. numberDigits++;
  40. }
  41. else if(c=='7'){
  42. numberDigits++;
  43. }
  44. else if(c=='8'){
  45. numberDigits++;
  46. }
  47. else if(c=='9'){
  48. numberDigits++;
  49. }
  50. }
  51. System.out.println("The number of digits is "+numberDigits+".");
  52. }
  53. }
Success #stdin #stdout 0.16s 321344KB
stdin
a121b34219c
stdout
Please enter a string: 
The number of digits is 8.