Problem:
The main subject is the processing of string input:
String A=cin.next ();
Char [] S=a.tochararray ();
String statisticsTime
limit:2000/1000 MS (java/others) Memory limit:65536/32768 K (java/others)
Total submission (s): 51624 Accepted Submission (s): 28327
Problem description for a given string, statistics the number of occurrences of a numeric character.
Input data has multiple lines, the first line is an integer n, indicating the number of test instances, followed by n rows, each containing a string consisting of letters and numbers.
Output for each test instance, outputs the number of values in the string, with each output occupying one row.
Sample Input
2asdfasdf123123asdfasdfasdf111111111asdfasdfasdf
Sample Output
69
Code:
Import java.util.*;p ublic class main{public static void Main (String args[]) {Scanner cin=new Scanner (system.in); while ( Cin.hasnext ()) {int n=cin.nextint (); for (int i=0;i<n;i++) {String a=cin.next (); Char [] s=a.tochararray (); int sum=0; for (int j=0;j<s.length;j++) {if (s[j]>= ' 0 ' &&s[j]<= ' 9 ') sum+=1;} SYSTEM.OUT.PRINTLN (sum);}}}
HDU 2017 string Statistics (Java)