-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCPRNumber.java
More file actions
51 lines (48 loc) · 1.14 KB
/
Copy pathCPRNumber.java
File metadata and controls
51 lines (48 loc) · 1.14 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
43
44
45
46
47
48
49
50
51
import java.util.*;
public class CPRNumber {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String cpr = sc.nextLine();
cpr = cpr.substring(0, cpr.indexOf("-")) + cpr.substring(cpr.indexOf("-")+1); //get rid of hyphen
int num = 0;
int sum = 0;
for (int i = 0; i < cpr.length(); i++) {
switch (i) {
case 0:
num = 4*Integer.parseInt(""+cpr.charAt(i));
break;
case 1:
num = 3*Integer.parseInt(""+cpr.charAt(i));
break;
case 2:
num = 2*Integer.parseInt(""+cpr.charAt(i));
break;
case 3:
num = 7*Integer.parseInt(""+cpr.charAt(i));
break;
case 4:
num = 6*Integer.parseInt(""+cpr.charAt(i));
break;
case 5:
num = 5*Integer.parseInt(""+cpr.charAt(i));
break;
case 6:
num = 4*Integer.parseInt(""+cpr.charAt(i));
break;
case 7:
num = 3*Integer.parseInt(""+cpr.charAt(i));
break;
case 8:
num = 2*Integer.parseInt(""+cpr.charAt(i));
break;
case 9:
num = Integer.parseInt(""+cpr.charAt(i));
break;
}
sum += num;
}
if(sum%11 == 0) System.out.println(1);
else System.out.println(0);
sc.close();
}
}