Last active
August 29, 2015 13:57
-
-
Save JorgeOlvera/9522735 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; | |
import java.io.*; | |
public class farthestPair { | |
public static void main(String [] args) { | |
Scanner input = new Scanner(System.in); | |
int a = input.nextInt(); | |
int c = a-1; | |
Random num = new Random(); | |
int [] array1 = new int [a]; | |
int [] array2 = new int [c]; | |
for (int b=0; b<array1.length; b++) { | |
array1[b] = num.nextInt(10); | |
} | |
for (int k=0; k<array1.length; k++) { | |
System.out.println(array1[k]); | |
System.out.println("--"); | |
} | |
soyUnFind(array1, array2, c); | |
} | |
public static void soyUnFind(int [] array1, int [] array2, int c) { | |
int f=0; | |
int g=1; | |
for (int d=0; d<c; d++) { | |
array2[d] = array1[f] - array1[g]; | |
f++; | |
g++; | |
} | |
for (int l=0; l<array2.length; l++) { | |
if (array2[l] <0) { | |
array2[l] = -array2[l]; | |
} | |
} | |
int highest =array2[0]; | |
int val1 = 0; | |
int val2 =0; | |
for (int h=0; h<array2.length; h++) { | |
if (array2[h] > highest) { | |
highest = array2[h]; | |
val2 = h; | |
val2 = h+1; | |
} | |
} | |
System.out.println("Pair with farthest values are " + val2 + " and " + val2 + " with a difference of " + highest); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment