diff --git a/GameOfAppsQ1.java b/GameOfAppsQ1.java new file mode 100644 index 0000000..1f12aa4 --- /dev/null +++ b/GameOfAppsQ1.java @@ -0,0 +1,46 @@ +/*Name: Kevin Lin + *Date: 4/20/2019 + *Purpose: To complete the Game of apps assignment of creating an algorithm + * that can find pairs in an aray that add up to a target sum + */ + + +public class GameOfAppsQ1{ + + public static void main(String[] args) { + + //Enter values here to find a result + int[] testArray = { 2, 4, 5, 1, 3, 5, 4 }; + int targetSum = 6; + + //calling the function + findPairs(testArray, targetSum); + } + + //defining the function + public static void findPairs(int[] testArray, int targetSum) { + //finding how many numbers are in the aray and initializing necessary variables and arrays + int size = testArray.length; + int solutionsFound = 0; + int[] pair1 = new int[size]; + int[] pair2= new int[size]; + + //searching for pairs and sticking them into two arrays, and also counting how many pairs have been found + for (int i=0;i