Skip to content

Instantly share code, notes, and snippets.

@pepet96
Created February 13, 2014 05:51
Show Gist options
  • Save pepet96/8970422 to your computer and use it in GitHub Desktop.
Save pepet96/8970422 to your computer and use it in GitHub Desktop.
import java.util.Scanner;
public class adjacent {
public static void main(String[] args){
Scanner input = new Scanner(System.in);
int positions = input.nextInt();
int myArray[] = new int [positions];
for (int i=0; i < positions;i++){
myArray[i] = input.nextInt();
}
int theanswer = adjacent(myArray);
if (theanswer == 1){
System.out.println("true");
}
else if (theanswer == 0){
System.out.println("false");
}
}
public static int adjacent(int[] myArray){
Scanner input = new Scanner (System.in);
int x = 0;
int x1 = 0;
int x2 = 0;
int x3 = 0;
for (int j=0; j <= myArray.length - 3; j++){
x1 = myArray[j];
x2 = myArray[j+1];
x3 = myArray[j+2];
}
int fox = x3 - x2;
int fox1 = x2 - x3;
if (fox == 1) {
x = 1;
}
else if(fox == -1){
x = 1;
}
else {
x = 0;
}
return x;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment