Question: Language- Java I was trying to do this, but I somehow was not able to get the correct output. I have posted what I have

 Language- Java I was trying to do this, but I somehow

Language- Java

I was trying to do this, but I somehow was not able to get the correct output. I have posted what I have done below. Please Help!

------------------------------------------------------------------------------------------------

public static void main(String[] args) { Scanner input= new Scanner(System.in); System.out.print("Enter a Social Security Number in the format 111-11-1111: "); String n1 =input.nextLine();

if(n1.length()==11){ if(Character.isDigit(n1.charAt(0)) && Character.isDigit(n1.charAt(1)) && Character.isDigit(n1.charAt(2)) && Character.isDigit(n1.charAt(3)) && Character.isDigit(n1.charAt(4)) && Character.isDigit(n1.charAt(5)) && Character.isDigit(n1.charAt(6)) && Character.isDigit(n1.charAt(7)) && Character.isDigit(n1.charAt(9)) && Character.isDigit(n1.charAt(9)) && Character.isDigit(n1.charAt(10)) && (n1.charAt(3)== '-') && (n1.charAt(6)== '-')){ System.out.print( n1 + "is an valid s1ocial security number."); } else { System.out.print( n1 + "is an invalid social security number."); } }else{ System.out.print( n1 + "is an invalid social security number."); }

Assignment 3 (1Opoints) Due Date: submit hard copy before class on Thursday 1/31/2019 Check Social Security Number Write a program that prompts the user to enter a Social Security number in the format 111-11-1111, where 1 is a digit. Your program should check whether the input is valid (Develop your program to display the result as the sample shown below) flere are Sample runs: Sample 1: Enter a Social Security Number in the format 111-11-1111: abc-11-3456 abc-11-3456 is an invalid social securitv number Sample 2: Enter a Social Security Number in the format 111-11-1111: 23-23-2345 23-23-2345 is an invalid social security number Sample 3.: Enter a Social Securitv Number in the format 111-11-1111: 234231234 234231234 is an invalid social security number Sample 4: Enter a Social Security Number in the format 111-11-1111: 232-23-5433 232-23-5433 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!