My assignment is to write a program that counts the number of times a digit is repeated in a phone number (numbers only). This is what I have so far and its output.
import java.util.Scanner;
public class PhoneNumber {
public static void main(String[] args) {
Scanner key= new Scanner(System.in);
String number;
int[] phoneArray = new int[10];
int one = 0;
System.out.println("Enter your phone number in the format (xxx)xxx-xxxx:");
number = key.nextLine();
for(int i = 0; i < phoneArray.length; i++) {
System.out.println("Count of " + i + "'s: " + number.charAt(i));
}
}
}
Output:
Enter your phone number in the format (xxx)xxx-xxxx:
(864)728-1638
Count of 0's: (
Count of 1's: 8
Count of 2's: 6
Count of 3's: 4
Count of 4's: )
Count of 5's: 7
Count of 6's: 2
Count of 7's: 8
Count of 8's: -
Count of 9's: 1
I'm not sure what I'm doing wrong.