Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I need to write a program that reads any character from user input. The program

ID: 3632655 • Letter: I

Question

I need to write a program that reads any character from user input. The program is then instructed to return either null or the numbers in a phone number format. The only valid digits the program will accept should be whitespace ("space" or " ") and the hyphen (-). Ultimately, however, the program will return the digits in phone number format. Any other character will result in the program returning null, and having to ask the user to enter a valid input. The program should only accept a 10 digit number. Examples of valid inputs are:

1234567890 //exactly ten digits
212-433-1999 //hyphens are accepted
2 5 7 2 6 8 9 1 0 1 // spaces are accepted
2-7-899912 36 //hyphens are spaces are sporadic, but still valid as it is programmed to accepted hyphens and space. it also has 10 digits

the output should look like this:
123-456-7890
212-433-1999
257-268-9101
278-999-1236
//notice they all come out as phone number format.

here are examples of invalid inputs:
(360)710-2638 //not programmed to accept parenthesis
nine one six (627)-9735 //not programmed to accepted these characters
916-619-916 //only nine digits, it must be ten digits long.

any invalid input should return a null value.

thanks for all the help guys.

Explanation / Answer

Hope this helps, please rate! import java.util.Scanner; public class phoneNumber { /** * @param args */ public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.print("Enter a phone number, it can contain - and numbers only: "); String input = sc.nextLine().trim(); int[] numList = new int[10]; int index = 0; while(true){ for(int i =1;i