Question: Hi, i am working on java program that shows if Social Security Number is valid. basicaly it check if statments, if there is 11 number

Hi,

i am working on java program that shows if Social Security Number is valid. basicaly it check "if" statments, if there is 11 number than if number 4 and 7 is '-' and another if stament to check that all of them is digit. so all this is already done, but one more question is to do this in the loop. and i have hard time about that. so it should loop until SSN will be invalid. if SSN is not then ask users to put again. this is what i have so far. (justt need to make it in the loop)

import java.util.Scanner;

public class SSN { public static void main(String[] args) { Scanner input = new Scanner(System.in);

System.out.println("Enter a Social Security Number"); String SSN = input.next(); if (SSN.length() ==11) { if (SSN.charAt(3) =='-' && SSN.charAt(6)== '-') { if (Character.isDigit(SSN.charAt(0)) &&Character.isDigit(SSN.charAt(1)) &&Character.isDigit(SSN.charAt(2)) &&Character.isDigit(SSN.charAt(4)) &&Character.isDigit(SSN.charAt(5)) &&Character.isDigit(SSN.charAt(7)) &&Character.isDigit(SSN.charAt(8)) &&Character.isDigit(SSN.charAt(9)) &&Character.isDigit(SSN.charAt(10))) { System.out.println("Valid SSN"); } } } else System.out.println("invalid SSN"); } }

Thanks

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!