programmingex4 21 java

Solutions on MaxInterview for programmingex4 21 java by the best coders in the world

showing results for - "programmingex4 21 java"
Lilith
28 Aug 2020
1import java.util.Scanner;
2 
3public class ProgrammingEx4_21 {
4 public static void main(String[] args) {
5  Scanner input = new Scanner(System.in);
6 
7  System.out.print("Enter a SSN:");
8  String s = input.nextLine();
9 
10  for (int i = 0; i < s.length(); i++) {
11   if ((i == 3 || i == 6) && s.charAt(i) == '-') {
12    continue;
13   }
14   if (!Character.isDigit(s.charAt(i))) {
15    System.out.println(s + " is an invalid social security number");
16    System.exit(0);
17   }
18  }
19 
20  System.out.println(s + " is a valid social security number");
21 }
22 
23}
24
similar questions
queries leading to this page
programmingex4 21 java