Question: A run is a sequence of adjacent repeated values. Write a program that generates a sequence of 20 random die tosses in an array and
A run is a sequence of adjacent repeated values. Write a program that generates a sequence of 20 random die tosses in an array and that prints the die values, marking the runs by including them in parentheses, like this:
1 2 (5 5) 3 1 2 4 3 (2 2 2 2) 3 6 (5 5) 6 3 1
its gotta use these methods
public class Sequence
{
private int[] values;
private int size;
public Sequence(int capacity)
{
values = new int[capacity];
size = 0;
}
public void add(int value)
{
if (size < values.length)
{
values[size] = value;
size++;
}
}
/**
* Returns the string of values, with runs enclosed in parentheses.
* @return the string of values with the runs marked
* for example "1 2 (5 5) 3 1 2 4 3 (2 2 2 2) 3 6 (5 5) 6 3 1"
*/
public String markRuns()
{
//your code here
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
