Skip to content

Instantly share code, notes, and snippets.

@JorgeOlvera
Created February 13, 2014 05:20
Show Gist options
  • Save JorgeOlvera/8970154 to your computer and use it in GitHub Desktop.
Save JorgeOlvera/8970154 to your computer and use it in GitHub Desktop.
/*Returntrueifthearraycontains,somewhere,threeincreasingadjacent numbers like 4, 5, 6 or 23, 24, 25.
tripleUp({1, 4, 5, 6, 2}) → true tripleUp({1, 2, 3}) → true tripleUp({1, 2, 4}) → false
public boolean tripleUp(int[] nums)*/
import java.util.Scanner;
public class uniqueAdjacent {
public static void main(String[] args){
Scanner input = new Scanner(System.in);
//Establish array length
System.out.println("Hey there. Please set the length of the array");
int positions = input.nextInt();
int myArray[] = new int [positions];
for (i=0; i<positions;i++){
myArray[i] = input.nextInt();
}
boolean theanswer = adjacent(myArray);
if (theanswer = true){
System.out.println("This set contains adjacent numbers");
}
else{
System.out.println("No adjacents");
}
}
public static boolean adjacent(int[] myArray){
Scanner input = new Scanner (System.in);
for (j=0; j>=0; j++){
int testA = myArray[j];
int testB = myArray[j+1];
int testC = myArray[j+2];
if (testC - testB = 1 || testB - testC = 1) {
return true;
}
else {
return false;
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment