-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSpecNumAdjacPairs.java
More file actions
25 lines (21 loc) · 962 Bytes
/
Copy pathSpecNumAdjacPairs.java
File metadata and controls
25 lines (21 loc) · 962 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
import java.util.*;
public class SpecNumAdjacPairs {
public static void main(String[] args) {
int[] array_nums = {10, 20, 10, 20, 40, 20, 50};
int result = 0; // Initialize a result variable
int x = 20; // The value to check for
// Iterate through the array, stopping at the second-to-last element
for (int i = 0; i < array_nums.length - 1; i++) {
// Check if the current element and the next element are not equal to the value 'x'
if (array_nums[i] != x && array_nums[i + 1] != x) {
result = 1; // If the condition is met, set the result to 1
}
}
// If result is still 0, it means no adjacent pairs without 'x' were found
if (result == 0) {
System.out.printf(String.valueOf(true)); // Print true
} else {
System.out.printf(String.valueOf(false)); // Print false
}
}
}