Java: Check if an array of integers contains a specified number next to each other or there are two same specified numbers separated by one element
Number Adjacent or Separated by One
Write a Java program to check if an array of integers contains a specified number next to each other or two same numbers separated by one element.
Pictorial Presentation:
Sample Solution:
Java Code:
Sample Output:
true
Flowchart:
For more Practice: Solve these Related Problems:
- Write a Java program to check if an array contains two consecutive numbers whose sum is a prime number.
- Write a Java program to check if an array contains a specified number at least twice, either adjacent or separated by one.
- Write a Java program to check if an array contains any two numbers that differ by exactly one.
- Write a Java program to find the longest sequence where numbers appear next to their half or double.
Go to:
PREV : 10 Before 20 Check.
NEXT : 20 Appears Thrice Non-Consecutively.
Java Code Editor:
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.