diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Part1_2.jpg b/Part1_2.jpg new file mode 100644 index 0000000..37c3cc8 Binary files /dev/null and b/Part1_2.jpg differ diff --git a/Part1_3.jpg b/Part1_3.jpg new file mode 100644 index 0000000..5c3648d Binary files /dev/null and b/Part1_3.jpg differ diff --git a/Part1_4.jpg b/Part1_4.jpg new file mode 100644 index 0000000..b72dcd3 Binary files /dev/null and b/Part1_4.jpg differ diff --git a/Part2_1.jpg b/Part2_1.jpg new file mode 100644 index 0000000..9077bc7 Binary files /dev/null and b/Part2_1.jpg differ diff --git a/Part3_2.jpg b/Part3_2.jpg new file mode 100644 index 0000000..6c18552 Binary files /dev/null and b/Part3_2.jpg differ diff --git a/README.md b/README.md index e759bf3..fc99154 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ * Is the **blank** object mutable or immutable? How can you tell? ```text -PUT ANSWER TO #2 HERE +blank is mutable because at first it was (1, 2) but later is changed to x and y ``` ```java @@ -47,7 +47,7 @@ public class Puzzler { * Explain how the return values from #3 and #4 differ. ```text -PUT ANSWER TO #5 HERE +#4 returns a number/numeric value of the distance between points ``` ```java @@ -87,14 +87,14 @@ Recall that aliases are two variables that refer to the same object. * Put the output in the text block below ```text -PUT ANSWER TO #2 HERE +(5, 8) (6, 9) ``` 3. At the end of main, are p1 and p2 aliased? Why or why not? * Put your answer in the text block below ```text -PUT ANSWER TO #3 HERE +No they output different points so they must be referencing different objects ``` ```java diff --git a/src/BigIntRewrite.java b/src/BigIntRewrite.java index 8f0dfce..c310dd0 100644 --- a/src/BigIntRewrite.java +++ b/src/BigIntRewrite.java @@ -1,5 +1,32 @@ +/** + * + * @author Trevor Hartman + * @author Andrew Escarcega + * + * @since 03/30/24 + * + */ + +import java.math.BigInteger; public class BigIntRewrite { - public static void main(String[] args) { + public static BigInteger pow(int x, int n) { + if (n == 0) return BigInteger.valueOf(1); + // find x to the n/2 recursively + BigInteger t = pow(x, n / 2); + // if n is even, the result is t squared + // if n is odd, the result is t squared times x + if (n % 2 == 0) { + return t.multiply(t); + } else { + return t.multiply(t).multiply(BigInteger.valueOf(x)); + } + } + public static void main(String[] args) { + int a = 3; + int b = 2; + BigInteger c = pow(a, b); + System.out.println(c); +//I'm not sure why but it highlights BigInteger, multiply and println in red saying there are errors but it works fine } } diff --git a/src/StringPlayground.java b/src/StringPlayground.java index a930a71..c9c4d86 100644 --- a/src/StringPlayground.java +++ b/src/StringPlayground.java @@ -1,4 +1,31 @@ +/** + * + * @author Trevor Hartman + * @author Andrew Escarcega + * + * @since 03/30/24 + * + */ + public class StringPlayground { + + public static int parenthesesCount(String s){ + //String s = "((3 + 7) * 2)"; + int count = 0; + for (int i = 0; i < s.length(); i++) { + char c = s.charAt(i); + if (c == '(') { count++; } + else if (c == ')') { count--; } + } + return count; + } + public static void main(String[] args) { + String s = "((3 + 7) * 2)"; + System.out.println(parenthesesCount(s)); + String s2 = "(((3 + 7) * 2)"; + System.out.println(parenthesesCount(s2)); + String s3 = "((3 + 7) * 2))"; + System.out.println(parenthesesCount(s3)); } } \ No newline at end of file