Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

Question on gettting an array to show a number that appears zero times

$
0
0
I have an assignment that basically asks me to create a program that counts the number of times a digit appears in an entered phone number. I have most of that done, but I'm struggling with how to get it to show number that appear zero times.

So let's say I enter 872-879-5498 (random number). I get:
Digit 2 showed up 1 times.
Digit 4 showed up 1 times.
Digit 5 showed up 1 times.
Digit 7 showed up 2 times.
Digit 8 showed up 3 times.
Digit 9 showed up 2 times.

When I need it to show 0,1, and 3 too.

Here's a piece of the code I've been working on
for (int i = 0; i < phoneyphone.length(); i++) {
int riVa = phoneyphone.charAt(i)-'0';
nCount[ riVa ]++;
}
for (int i = 0; i < nCount.length; i++) {
if( nCount[i] != 0 ) {
System.out.printf("Digit %d showed up %d%n times. " , i, nCount[i]);
}



Any help would be appreciated.

Viewing all articles
Browse latest Browse all 51036

Trending Articles