Last active
October 18, 2017 02:14
-
-
Save thmain/5b2140f14b567c6c7621d9fd4d07a664 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
import java.util.Arrays; | |
public class NutsAndBoltsBruteForce { | |
public static void match(char [] nuts,char [] bolts){ | |
for (int i = 0; i <nuts.length ; i++) { | |
char nut = nuts[i]; | |
for (int j = 0; j <bolts.length ; j++) { | |
if(nut==bolts[j]){ | |
swap(bolts,i,j); | |
break; | |
} | |
} | |
} | |
System.out.println("Matched nuts and bolts are: "); | |
System.out.println(Arrays.toString(nuts)); | |
System.out.println(Arrays.toString(bolts)); | |
} | |
public static void swap(char [] bolts, int i, int j){ | |
char temp = bolts[i]; | |
bolts[i] = bolts[j]; | |
bolts[j] = temp; | |
} | |
public static void main(String[] args) { | |
char [] nuts = {'$', '%', '&', 'x', '@'}; | |
char [] bolts = {'%', '@', 'x', '$', '&'}; | |
match(nuts,bolts); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment