Skip to content

Instantly share code, notes, and snippets.

@thmain
Created August 28, 2017 02:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thmain/f99a273ff941d32c2ab423ce12d97e7d to your computer and use it in GitHub Desktop.
Save thmain/f99a273ff941d32c2ab423ce12d97e7d to your computer and use it in GitHub Desktop.
public class ThreeNumbersSumZeroBruteForce {
public static void find(int [] a){
for (int i = 0; i <a.length ; i++) {
for (int j = i+1; j <a.length ; j++) {
for (int l = j+1; l <a.length ; l++) {
if(a[i]+a[j]+a[l]==0){
System.out.println("Found 3 elements whose sum is = 0");
System.out.println("Elements are " + a[i] + " " + a[j]+ " " + a[l]);
return;
}
}
}
}
System.out.println("Did not find 3 elements whose sum is = 0");
}
public static void main(String[] args) {
int a [] = { 3,-1,-7,-4,-5,9,10};
find(a);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment