-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathResistorColorDuo.java
More file actions
56 lines (54 loc) · 1.71 KB
/
Copy pathResistorColorDuo.java
File metadata and controls
56 lines (54 loc) · 1.71 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
class ResistorColorDuo {
int value(String[] colors) {
String result = "";
int iter = 0;
int maxIter = 2; //Two goes round
for (String color : colors){
if (iter < maxIter){
switch(color){
case "black":
result += '0';
iter++;
break;
case "brown":
result += '1';
iter++;
break;
case "red":
result += '2';
iter++;
break;
case "orange":
result += '3';
iter++;
break;
case "yellow":
result += '4';
iter++;
break;
case "green":
result += '5';
iter++;
break;
case "blue":
result += '6';
iter++;
break;
case "violet":
result += '7';
iter++;
break;
case "grey":
result += '8';
iter++;
break;
case "white":
result += '9';
iter++;
break;
}
} else{ break; }
}
return Integer.parseInt(result); //Turn String to an Int
}
}