Created
August 28, 2017 01:22
-
-
Save thmain/28d5c970ebf41ee426c36167458591be to your computer and use it in GitHub Desktop.
This file contains 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
public class ThreeNumbersSumKBruteForce { | |
public static void find(int [] a, int k){ | |
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]==k){ | |
System.out.println("Found 3 elements whose sum is = " +k); | |
System.out.println("Elements are " + a[i] + " " + a[j]+ " " + a[l]); | |
return; | |
} | |
} | |
} | |
} | |
System.out.println("Did not find 3 elements whose sum is = " +k); | |
} | |
public static void main(String[] args) { | |
int a [] = { 3,1,7,4,5,9,10}; | |
int k = 21; | |
find(a,k); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment