-
Notifications
You must be signed in to change notification settings - Fork 133
Expand file tree
/
Copy pathRomanNumerals.java
More file actions
104 lines (96 loc) · 2.05 KB
/
Copy pathRomanNumerals.java
File metadata and controls
104 lines (96 loc) · 2.05 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
public class RomanNumerals {
public int convertToInteger(String romanNum) {
// To be Implemented
return 0;
}
public static int convert(String string) {
// TODO Auto-generated method stub
return 2;
}
public static boolean checkCharacters(String string) {
// TODO Auto-generated method stub
for(int i=0; i<string.length(); i++){
char ch = string.charAt(i);
if(ch != 'I' & ch != 'V' & ch != 'X' & ch != 'L' & ch != 'C' & ch != 'D' & ch != 'M')
return false;
}
return true;
}
public static boolean checkRepetition3(String string) {
// TODO Auto-generated method stub
int I = 0,X = 0 ,C = 0,M = 0;
for(int i=0; i<string.length(); i++){
char ch = string.charAt(i);
switch(ch){
case 'I':
I += 1;
break;
case 'X':
X += 1;
break;
case 'C':
C += 1;
break;
case 'M':
M += 1;
break;
}
if (I == 3 | X == 3 | C == 3 | M == 3)
return false;
}
return true;
}
public static boolean checkRepetition2(String string) {
// TODO Auto-generated method stub
int V = 0,L = 0 ,D = 0;
for(int i=0; i<string.length(); i++){
char ch = string.charAt(i);
switch(ch){
case 'V':
V += 1;
break;
case 'L':
L += 1;
break;
case 'D':
D += 1;
break;
}
if (V == 2 | L == 2 | D == 2)
return false;
}
return true;
}
public static char checkSubstraction(String string) {
// TODO Auto-generated method stub
for(int i=0; i<string.length()-1; i++){
char ch = string.charAt(i);
char ch2 =string.charAt(i+1);
switch(ch){
case 'I':
if(ch2 == 'X'|ch2 == 'V')
return ch;
break;
case 'X':
if(ch2 == 'L'|ch2 == 'C')
return ch;
break;
case 'C':
if(ch2 == 'D'|ch2 == 'M')
return ch;
break;
}
}
return ' ';
}
public static boolean oneSubstraction(String string) {
// TODO Auto-generated method stub
for(int i=0; i<string.length()-1; i++){
char ch = string.charAt(i);
char ch2 = string.charAt(i+1);
if((ch == ch2) & (string.charAt(i+2) != '\u0000'))
return false;
}
return true;
}
}