-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathThree_Incre_Adjace_Numbers.java
More file actions
36 lines (27 loc) · 1.17 KB
/
Copy pathThree_Incre_Adjace_Numbers.java
File metadata and controls
36 lines (27 loc) · 1.17 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
import java.util.*;
public class Three_Incre_Adjace_Numbers{
public static void main(String[] args) {
// Initialize an integer array with some values
int[] array_nums = {11, 12, 13, 14, 45, 20};
// Print the original array
System.out.println("Original Array: " + Arrays.toString(array_nums));
// Initialize a result variable to 1
int result = 1;
// Iterate through the array to check for consecutive integers
for (int i = 0; i <= array_nums.length - 3; i++) {
// Check if the current number, the next, and the one after that are consecutive
if (array_nums[i] + 1 == array_nums[i + 1] && array_nums[i + 1] + 1 == array_nums[i + 2]) {
// If they are consecutive, set the result to 0
result = 0;
}
}
// Check the result and print either true or false
if (result == 1) {
System.out.printf(String.valueOf(false));
} else {
System.out.printf(String.valueOf(true));
}
// Print a newline character for formatting
System.out.printf("\n");
}
}