Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions GameOfAppsQ1.java
Original file line number Diff line number Diff line change
@@ -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<size;i++){
for(int j =i+1;j<size;j++){
if((testArray[i]+testArray[j])==targetSum){
pair1[solutionsFound]=testArray[i];
pair2[solutionsFound]=testArray[j];
solutionsFound++;
}
}
}
//printing out the pairs
System.out.println("Solutions found: "+solutionsFound);
for(int k=0;k<solutionsFound;k++){
System.out.println("Pair #"+(k+1)+" "+pair1[k]+","+pair2[k]);
}
}


}
38 changes: 38 additions & 0 deletions GameOfAppsQ2.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*Name: Kevin Lin
*Date: 4/20/2019
*Purpose: To complete the gameofapps task of checking if a word is a palindrome
*/


public class GameOfAppsQ2{

public static void main(String[] args) {

//Enter values here to find a result
String testString1="racecar";

//calling the function
boolean String1 = isPalindrome(testString1);
if(String1==true){
System.out.println(testString1+" is a palindrome");
} else {
System.out.println(testString1+" is NOT a palindrome");
}
}

//defining the function
static boolean isPalindrome(String testString) {
int length=testString.length();
int halfLength=length/2;
char[] stringToCharArray=testString.toCharArray();
for (int i=0;i<halfLength;i++){
if(!(stringToCharArray[i]==stringToCharArray[length-i-1])){
return false;
}
}
return true;

}


}