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
6 changes: 6 additions & 0 deletions .idea/vcs.xml

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

15 changes: 14 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

```text
PUT ANSWER TO #2 HERE
- The object is immutable
because it's a string.
```

```java
Expand Down Expand Up @@ -48,6 +50,12 @@ public class Puzzler {

```text
PUT ANSWER TO #5 HERE
- The return value from
#3 was blank and returns
to the point instance,
but #4 returns 5.0 and
does not connect back
to anything
```

```java
Expand Down Expand Up @@ -88,13 +96,18 @@ Recall that aliases are two variables that refer to the same object.

```text
PUT ANSWER TO #2 HERE
- (5, 8)
(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
- No because all of the
frames are not overlapp
ing.
```

```java
Expand Down Expand Up @@ -142,7 +155,7 @@ for (int i = 0; i < s.length(); i++) {
* Screenshot your output and add it to your project as Part3_2.jpg
3. Generalize the code so that it works on any string.
* What could you do to generalize it more?

* Turn the s variable to a scanner input, so any string may be used in the program.
## Part 4: Large Numbers

Many encryption algorithms depend on the ability to raise large integers to a power. Below is a method that implements an efficient algorithm for integer exponentiation:
Expand Down
14 changes: 14 additions & 0 deletions src/BigIntRewrite.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,18 @@
import java.math.BigInteger;
public class BigIntRewrite {

public static BigInteger pow(int x, int n) {
if (n==0) return BigInteger.valueOf(1);

BigInteger a = pow(x, n/2);

if (n%2 == 0) {
return a.multiply(a);
}
else {
return a.multiply(a).multiply(BigInteger.valueOf(x));
}
}
public static void main(String[] args) {

}
Expand Down
Binary file added src/Part1_2.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/Part1_3.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/Part1_4.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/Part2_1.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 9 additions & 0 deletions src/StringPlayground.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
public class StringPlayground {

public static void main(String[] args) {
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--; }
}
System.out.println();
}
}