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
74 changes: 74 additions & 0 deletions FindAllPairs.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package com.company;

import java.util.ArrayList;
import java.util.Arrays;

public class FindAllPairs {
public static void findPairs(int[] testArray, int targetSum){
ArrayList<Integer> newArray = new ArrayList<Integer>();
//Array to store new sorted list without duplicates

Arrays.sort(testArray);
//Sorts test Array
//(1,2,4,4,5,5)

newArray.add(testArray[0]);
//Adds first element of testArray to the Arraylist

boolean targetSumHalf = false;
//boolean if exists a pair of numbers that are the same value, but added up equal targetSum

for (int i = 0; i < testArray.length-1; i ++){
//If there are a pair of duplicates (Pairs where both the numbers are the same, but their sums equal targetSum),
//they are counted as a pair.
if (newArray.get(newArray.size()-1)!=testArray[i+1]){
//Since list is expanding, checks previously added element with the testArray
newArray.add(testArray[i+1]);
//Adds testArray element if its unique to the recently added Arraylist element
}
else{
if (testArray[i+1]*2 == targetSum && targetSumHalf == false ){
System.out.println ("("+ newArray.get(newArray.size()-1)+","+ testArray[i+1]+")");
targetSumHalf = true;
}
}
}
//Now uses newArray, which has list with non-duplicate numbers
//(1,2,4,5)

//Starting at ends of the newArray
int start = 0;
int end = newArray.size()-1;

//Keeps on looping until the two ends have met.
while (start < end){
int sum = newArray.get(start) + newArray.get(end);

//checking if sum of the start and end index elements are equal to target sum
if (sum == targetSum){
//prints the pair, increments start and decrements end and continues
System.out.println ("("+ newArray.get(start)+","+ newArray.get(end)+")");
start++;
end--;
}
else if (sum < targetSum){
//if sum is less than targetSum, range moves up to use bigger numbers for comparison.
start++;
}
else{
// If sum is more than targetSum, range moves down to use smaller numbers.
end--;
}
}
}
public static void main(String[] args){
//Example values
int[] testArray = {2, 4, 5, 1, 3, 5, 4};
int targetSum = 6;

//Values to be printed on the console are
//(2,4)
//(1,5)
findPairs(testArray, targetSum);
}
}
26 changes: 26 additions & 0 deletions Palindrome.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
public class Palindrome{
public static boolean isPalindrome(String testString){
//starts at both ends of the word. Compares each letter and gets close to the middle letters.
//loop ends in the middle of the word.
//If its odd number of characters or word is one letter, middle letter is avoided.
for (int i = 0; i < testString.length()/2; i ++){
//If the two chars are not the same letter, return false
if (testString.charAt(i) != testString.charAt(testString.length()-i-1)){
return false;
}
}
//All letters of the word have been compared and resemble a palindrome
return true;
}
public static void main(String[] args) {
//Words that return true (Taken from question)
System.out.println(isPalindrome("radar"));
System.out.println(isPalindrome("bob"));
System.out.println(isPalindrome("asdfdsa"));

//Words that return false (I made these up)
System.out.println(isPalindrome("apple"));
System.out.println(isPalindrome("love"));
System.out.println(isPalindrome("asdsdfdsafdsgfherfdsa"));
}
}
14 changes: 14 additions & 0 deletions PictureApp/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
*.iml
.gradle
/local.properties
/.idea/caches
/.idea/libraries
/.idea/modules.xml
/.idea/workspace.xml
/.idea/navEditor.xml
/.idea/assetWizardSettings.xml
.DS_Store
/build
/captures
.externalNativeBuild
.cxx
116 changes: 116 additions & 0 deletions PictureApp/.idea/codeStyles/Project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions PictureApp/.idea/codeStyles/codeStyleConfig.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions PictureApp/.idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 25 additions & 0 deletions PictureApp/.idea/jarRepositories.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions PictureApp/.idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions PictureApp/.idea/runConfigurations.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions PictureApp/.idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions PictureApp/app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
32 changes: 32 additions & 0 deletions PictureApp/app/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
apply plugin: 'com.android.application'

android {
compileSdkVersion 29

defaultConfig {
applicationId "com.example.pictureapp"
minSdkVersion 28
targetSdkVersion 29
versionCode 1
versionName "1.0"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}

buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}

dependencies {
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'

}
21 changes: 21 additions & 0 deletions PictureApp/app/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
Loading