Skip to content

Commit

Permalink
Rolls done
Browse files Browse the repository at this point in the history
  • Loading branch information
jaypatel208 committed Nov 29, 2023
1 parent 6ffd3c8 commit 68f47fd
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/RefereneCheck.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import edu.princeton.cs.algs4.Counter;

public class RefereneCheck {
public static void main(String[] args) {
Counter c1 = new Counter("One");
System.out.println("c1 before increment: " + c1);
c1.increment();
System.out.println(("c1 after increment: ") + c1);
Counter c2 = c1;
System.out.println("c2 before increment: " + c2);
c2.increment();
System.out.println("c2 after increment: " + c2);
// here to c2 we gave reference of c1 so increasing c2 will increase value of c1 too
System.out.println("c1 at the end: "+c1);
}
}
23 changes: 23 additions & 0 deletions src/Rolls.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import edu.princeton.cs.algs4.Counter;
import edu.princeton.cs.algs4.StdRandom;

public class Rolls {
public static void main(String[] args) {
int T = Integer.parseInt(args[0]);
int SIDES = 6;
Counter[] rolls = new Counter[SIDES + 1];

for (int i = 1; i <= SIDES; i++) {
rolls[i] = new Counter(i + "'s");
}

for (int t = 0; t < T; t++) {
int result = StdRandom.uniformInt(1, SIDES + 1);
rolls[result].increment();
}

for (int i = 1; i <= SIDES; i++) {
System.out.println(rolls[i]);
}
}
}

0 comments on commit 68f47fd

Please sign in to comment.