Created
February 13, 2014 05:51
-
-
Save pepet96/8970422 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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