-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFeb_13_Codingbat.java
More file actions
30 lines (23 loc) · 919 Bytes
/
Feb_13_Codingbat.java
File metadata and controls
30 lines (23 loc) · 919 Bytes
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
package Daily_Problem;
public class Feb_13_Codingbat {
public static void main(String[] args) {
// Example array
int[] exampleArray1 = {1, 2, 2, 3, 4, 4, 5};
int[] exampleArray2 = {1, 2, 3, 4, 5};
Feb_13_Codingbat myInstance = new Feb_13_Codingbat();
boolean result1 = myInstance.either24(exampleArray1);
System.out.println("Result for exampleArray1: " + result1);
boolean result2 = myInstance.either24(exampleArray2);
System.out.println("Result for exampleArray2: " + result2);
}
public boolean either24(int[] nums) {
int count = 0;
for (int i = 0; i < nums.length - 1; i++) {
if (nums[i] == 2 && nums[i + 1] == 2)
count++;
if (nums[i] == 4 && nums[i + 1] == 4)
count++;
}
return count == 1;
}
}