-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExercise04_21.java
More file actions
42 lines (34 loc) · 1.09 KB
/
Copy pathExercise04_21.java
File metadata and controls
42 lines (34 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import java.util.Scanner;
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author jorda
*/
public class Exercise04_21 {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.println("Enter a SSN: ");
String SSN = input.nextLine();
if(checkSSN(SSN))
System.out.println(SSN + " is a valid social security number");
else
System.out.println(SSN + " is an invalid social security number");
}
public static boolean checkSSN(String SSN){
SSN.trim();
if(SSN.charAt(3) == '-' && SSN.charAt(6) == '-'){
for (int i = 0; i < SSN.length(); i++) {
if(i == 3 | i == 6)
continue;
if(!(Character.isDigit(SSN.charAt(i))))
return false;
}
return true;
}else
return false;
}
}