Question: 4.21 (Check SSN) Write a program that prompts the user to enter a Social Security number in the format DDD-DD-DDDD, where D is a digit.

4.21 (Check SSN) Write a program that prompts the user to enter4.21 (Check SSN) Write a program that prompts the user to enter a Social Security number in the format DDD-DD-DDDD, where D is a digit. Your program should check whether the input is valid. Here are sample runs:

this is my code, but it won't work. If you can correct it, and put it in the code in the right way, it would help me a lot.

19 20 21 public static void main (String[] args) i / TODo code application logic here Scanner input - new Scanner (System.in) System.out.print ("Enter a SSN: "); String sinput.nextLine ) 23 if (s.length ) -11) 25 if (s.indexof ('-'!- 27 s. last IndexOf (-') !-6) System.out.println (s+ "is an invalid" + 30 31 32 " social security number") else if (Character.isDigit(s.charAt ! Character . sDigitis. charAt (1 (0)) && !Character.isDigit (s.charAt (2)) &s Character.isDigit(s.charAt (4) && !Character.isDigit (s.charAt (5)) & Character.isDigit(s.charAt (7) && !Character.isDigit (s.charAt (8)) & Character.isDigit(s.charAt (9) && Character.isDigit (s.charAt (10 35 40 43 System.out.println (s+ " is an invalid" +social secuirty number") else 46 47 System.out.println(s+ " is a valid"+ "social security number")

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!