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/README.md b/README.md index e759bf3..b1f9b2d 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 +PUT ANSWER TO #2 HERE: The object is mutable because it can be changed. ``` ```java @@ -47,7 +47,7 @@ public class Puzzler { * Explain how the return values from #3 and #4 differ. ```text -PUT ANSWER TO #5 HERE +PUT ANSWER TO #5 HERE: #3 is a point object. #4 is a double. ``` ```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 +PUT ANSWER TO #2 HERE: (5,8) ``` 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 +PUT ANSWER TO #3 HERE: P1 and P2 are not aliased since they are different objects. ``` ```java diff --git a/src/BigIntRewrite.java b/src/BigIntRewrite.java index 8f0dfce..b234a56 100644 --- a/src/BigIntRewrite.java +++ b/src/BigIntRewrite.java @@ -1,5 +1,28 @@ +import java.math.BigInteger; + public class BigIntRewrite { + public static BigInteger pow(int x, int n) { + BigInteger result = BigInteger.ONE; + BigInteger number = BigInteger.valueOf(x); + + while (n > 0) { + if (n % 2 == 1) { + result = result.multiply(number); + } + number = number.multiply(number); + n /= 2; + } + + + return result; + } + public static void main(String[] args) { + int number = 2; + int exponent = 10; + BigInteger result = pow(number, exponent); + + System.out.println(number + " raised to the power of " + exponent + " is: " + result); } } diff --git a/src/P3_2.png b/src/P3_2.png new file mode 100644 index 0000000..e63a89b Binary files /dev/null and b/src/P3_2.png differ diff --git a/src/StringPlayground.java b/src/StringPlayground.java index a930a71..aec6f7a 100644 --- a/src/StringPlayground.java +++ b/src/StringPlayground.java @@ -1,4 +1,26 @@ public class StringPlayground { + + public static int countParentheses(String s) { + 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[] testStrings = {"((3 + 7) * 2)", "((3 + 7) * 2))"}; + + for (String testString : testStrings) { + int result = countParentheses(testString); + + System.out.println("String: " + testString + ", Parentheses count: " + result); + } } } \ No newline at end of file diff --git a/src/p1_2.png b/src/p1_2.png new file mode 100644 index 0000000..1668414 Binary files /dev/null and b/src/p1_2.png differ diff --git a/src/p1_3.png b/src/p1_3.png new file mode 100644 index 0000000..fa2680c Binary files /dev/null and b/src/p1_3.png differ diff --git a/src/p1_4.png b/src/p1_4.png new file mode 100644 index 0000000..51eeb98 Binary files /dev/null and b/src/p1_4.png differ diff --git a/src/p2_1.png b/src/p2_1.png new file mode 100644 index 0000000..a37e04f Binary files /dev/null and b/src/p2_1.png differ