Question: 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
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.
//Hint: Use charAt() and isDigit() methods.
Java
Driver main.java
public static void main(String args[]){ ProblemSolution problemSolution = new ProblemSolution(); // Print the result if(problemSolution.isValid()) System.out.print("Valid SSN"); else System.out.print("Invalid SSN"); } }
Problemsolution.java
import java.util.*; import java.lang.*; import java.io.*; class ProblemSolution{ public boolean isValid(){ // Write your code here // Read the SSN Scanner input = new Scanner(System.in);
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
