*4.21(检查 SSN)编写一个程序,提示用户输入一个社保号码,它的格式是DDD-DD-DDDD,其中D是一个数字。你的程序应该判断输入是否合法。
下面是一个运行示例:
Enter a SSN: 232-23-5435
232-23-5435 is a valid social security number
Enter a SSN: 23-23-5435
23-23-5435 is an invalid social security number
*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. Your program should check whether the input is valid.
Here are sample runs:
Enter a SSN: 232-23-5435
232-23-5435 is a valid social security number
Enter a SSN: 23-23-5435
23-23-5435 is an invalid social security number
下面是参考答案代码:
import java.util.*;
public class CheckSSNQuestion21 {
public static void main(String[] args) {
String ssnString;
System.out.print