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
/** | |
Given a set of numbers -50 to 50, find all pairs that add up to a given sum. | |
* Created by kylel95 on 11/3/18. | |
*/ | |
import java.util.*; | |
public class fiftysum { | |
public static void main(String [] args){ | |
int [] arr = new int[101]; | |
int index = 0; | |
for(int i = -50; i <= 50; i++){ |
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
/** | |
* Created by kylel95 on 11/22/18. | |
*/ | |
import java.util.*; | |
public class balancedNumber { | |
// Write a function to determine if the frequency of digits in a given number is balanced. | |
public static void main (String [] args){ | |
System.out.println(freq(1337)); | |
System.out.println(freq(3.1415926535)); | |
System.out.println(freq(12345678)); |
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
/** | |
* Created by kylel95 on 12/13/18. | |
*/ | |
import java.io.*; | |
import java.util.*; | |
/** | |
* Calculate number of non-prime factors of a number N | |
*/ | |
public class nonprimefactors { |
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
/** | |
* Created by kylel95 on 12/5/18. | |
*/ | |
import java.io.BufferedReader; | |
import java.io.InputStreamReader; | |
import java.util.*; | |
public class day5 { | |
public static void main(String [] args) { | |
Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in))); |
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
/** | |
* Created by kylel95 on 12/24/18. | |
*/ | |
public class greaterPower { | |
public static void main(String [] args){ | |
int a = 3; | |
int b = 5; | |
int c = 2; | |
int d = 4; | |
System.out.println(greaterPow(a, b)); |
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
- What is the difference between passing by value and passing by reference? | |
By value: Passes the value of the memory address that the pointer points to. | |
By reference: Passes an alias to “reference” the variable passed in. | |
- How can pointers be used with inherited or abstract classes? | |
Using static methods. | |
- What does it mean for a pointer to be null? | |
The pointer does not point to any address in memory. | |
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.*; | |
/** | |
* Returns all numbers < n whose digits are 1 or 5. | |
* Created by Kyle Long on 1/14/19. | |
*/ | |
public class oneFive { | |
public static void main(String [] args){ | |
Scanner scan = new Scanner(System.in); | |
int n = scan.nextInt(); |
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.regex.*; | |
/** | |
* Created by kylel95 on 1/22/19. | |
*/ | |
public class repeatedSubString { | |
public static void main(String [] args){ | |
System.out.println(repeat("pi", "pipipipi")); | |
System.out.println(repeat("danger", "cassidy")); |
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
Functional Programming | |
---------------------- | |
Throughout our daily or weekly lives, we often do several tasks repeatedly. For example, brushing your teeth, | |
introducing yourself to a stranger, making your bed, etc. It would be very convenient if we could snap our fingers | |
and say, "Make my bed" after every night’s rest. Unfortunately, this is not (yet) the case. Well, in programming, there are | |
task that programmers know they will have to do over and over again. Maybe calculating the number of days until Christmas, checking if a number is prime, counting letters in a word, etc. It is often very useful to create functions or blocks of reusable code that a program can invoke to execute a this consistent task instead of writing out the code every single time. Instead of writing code and figuring out the logic everytime, functions can be created. For example, static int numOfLetters(String s) { return s.length();}, calculate how long the word (string) s is. Instead of having to rememver the syntax (s.length()), a p |
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
/** | |
* Created by Kyle Long on 2/12/19. | |
*/ | |
public class charsToPalindrome { | |
public static void main(String [] args){ | |
String s = "hi"; //hi -> hih or ihi | |
String s1 = "xx"; //already palindrome | |
String s2 = "race"; //racecar | |
String s3 = "abcdabc"; //not possible to convert into a palindrome | |
System.out.println(makeAPal(s)); |
OlderNewer