Can somebody check my codes?(Counting numbers)
This program is about counting the number of digits that exist in a string
there is no compile error on it but there is an error in the logics that i cant find it. So can somebody have a look at it, if you cant tell me the direct answer then please give me some hints. Thanks
Here is my codes
Code:
public class OccurrenceString
{
public static void main (String[] args)
{
System.out.println("SSN is 343 32 4545 and ID is 434 34 4323");
String SSNandID = "SSN is 343 32 4545 and ID is 434 34 4323";
int[] countNum = count(SSNandID);
//display count array
for(int i=0; i < countNum.length; i++)
{
if(countNum[i] != 0)
System.out.println(i +" appears "+ countNum[i] + ((countNum[i]==1)?" times.":" times."));
}
}//end of main
public static int[] count(String SSNandID)
{
int counts[] = new int[10];
for(int i = 0; i< SSNandID.length(); i++)
{
if(Character.isDigit(SSNandID.charAt(i)))
{
counts[SSNandID.charAt(i)]++;
}
}//end of for
return counts;
}//end of count method
}//end of OccurrenceString