Skip to content

Instantly share code, notes, and snippets.

@pepet96
Created January 31, 2014 15:06
Show Gist options
  • Save pepet96/8733753 to your computer and use it in GitHub Desktop.
Save pepet96/8733753 to your computer and use it in GitHub Desktop.
import java.util.Scanner;
public class largest {
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 < myArray.length; i++){
myArray[i] = input.nextInt();
}
int greatestvalue = maxTriple(myArray);
System.out.println(greatestvalue);
}
public static int maxTriple (int [] myArray){
int a = myArray[0];
int c = myArray[myArray.length - 1];
int b = myArray[(myArray.length/2)+1];
int greater = 0;
if ( a > b && a > c){
greater = a;
}
else if ( b > a && b > c){
greater = b;
}
else if ( c > a && c > b){
greater = c;
}
return greater;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment