Skip to content

Instantly share code, notes, and snippets.

class DoublePointer {
String s;
public DoublePointer(String s){
this.s = s;
}
}
public class IdentitySwitch {
public static void main(String[] args) {
DoublePointer dp = new DoublePointer("unchanged");
public class IdentitySwitch {
public static void main(String[] args) {
String s = "unchanged";
System.out.println(s);
foo(s);
System.out.println(s);
}
public void foo(String s) {
s = "changed"
String s1("1");
String s2("2");
cout << s1 << s2 << endl;
class A {
protected int a;
public A() {
a = 10;
}
}
class B extends A {
private int b;
public B() {
@rshepherd
rshepherd / Rectangle.java
Last active August 29, 2015 14:11
OOP practice problem
// Let me know if you see any mistakes!!
public class Rectangle {
private int length;
private int width;
public Rectangle() {}
public Rectangle(int width, int length) {
@rshepherd
rshepherd / FinalReview.java
Last active August 29, 2015 14:11
Final review on data structures
import java.util.*;
// Let me know if you find any mistakes!!
public class FinalReview {
public static void main(String[] args) {
System.out.println("Question 1:");
List<String> list = new ArrayList<>();
list.add("1");
@rshepherd
rshepherd / StackExercises.java
Last active August 29, 2015 14:11
Some practice with Stacks
public class StackExercises {
public static void main(String[] args) {
// Reverse
System.out.println("Reverse:");
System.out.println(
"12345 => " + reverse("12345") + '\n' +
"randy => " + reverse("randy") + '\n' +
"2 => " + reverse("2")
);
@rshepherd
rshepherd / BigO.java
Created November 23, 2014 17:20
Intro to Big O notation
public class BigO {
// Big O notation is used in Computer Science to describe the performance or complexity of an algorithm.
// Big O specifically describes the worst-case scenario, and can be used to describe
// the execution time required or the space used
// O(1) describes an algorithm that will always execute in the same time (or space)
// regardless of the size of the input data set.
private String[] strings = { "", null };
@rshepherd
rshepherd / Recursion.java
Created November 23, 2014 17:18
Code snippets from recursion lecture
public class Recursion {
public static class ExampleOne
{
public static void main (String args[])
{
count(0);
}
public static void count (int index)
@rshepherd
rshepherd / TestDigitalWallet.java
Created November 22, 2014 22:06
Solution to practice midterm
public class TestDigitalWallet {
public static void main(String[] args) {
DigitalWallet w1 = new DigitalWallet(1);
w1.deposit(10000);
w1.withdraw(5000);
DigitalWallet.setMaxWithdrawalPct(.75);
System.out.println(w1.canWithdraw(4000)); // false
DigitalWallet w2 = new DigitalWallet(2, 20000);