Write a function in Java that implements the following logic: Given 2 ints, a and b, return their sum. However, sums in the range 10..19...

# Exercises

Write a function in Java that implements the following logic: Given three ints, a b c, return true if one of them is 10 or more less than...

Write a function in Java that implements the following logic: Given a number n, return true if n is in the range 1..10, inclusive. Unless...

Write a function in Java that implements the following logic: We are having a party with amounts of tea and candy. Return the int outcome...

Write a function in Java that implements the following logic: Your cell phone rings. Return true if you should answer it. Normally you...

Write a function in Java that implements the following logic: Given a string name, e.g. "Bob", return a greeting of the form "Hello...

Write a function in Java that implements the following logic: Given a string, return true if it ends in "ly".

Write a function in Java that implements the following logic: Given a string, if the string begins with "red" or "blue" return that color...

Write a function in Java that implements the following logic: The web is built with HTML strings like "<i>Yay</i>" which...

Write a function in Java that implements the following logic: Given 2 strings, a and b, return a string of the form short+long+short,...

Write a function in Java that implements the following logic: Given 2 ints, `a`

and `b`

, return their sum. However, "teen" values in the...

Write a function in Java that implements the following logic: The squirrels in Palo Alto spend most of the day playing. In particular,...

Write a function in Java that implements the following logic: You are driving a little too fast, and a police officer stops you. Write...

Write a function in Java that implements the following logic: Given a non-negative number `num`

, return true if `num`

is within 2 of a...

Write a function in Java that implements the following logic: Given three ints, `a`

, `b`

, and `c`

, return true if `b`

is greater than `a`

, and `c`

is...

Write a function in Java that implements the following logic: Given three ints, `a`

, `b`

, and `c`

, return true if it is possible to add two of...

Write a function in Java that implements the following logic: You have a red lottery ticket showing ints `a`

, `b`

, and `c`

, each of which is 0,...

Write a function in Java that implements the following logic: You have a blue lottery ticket, with ints `a`

, `b`

, and `c`

on it. This makes...

Write a function in Java to implement the following logic: We want to make a row of bricks that is `goal`

inches long. We have a number of...

Write a function in Java that implements the following logic: Given 3 int values, `a`

, `b`

, and `c`

, return their sum. However, if one of the...

Write a function in Java that implements the following logic: Given 3 int values, `a`

, `b`

, and `c`

, return their sum. However, if one of the...

Write two methods in Java that implements the following logic: Given 3 int values, `a`

, `b`

, and `c`

, return their sum. However, if any of the...

Write a function in Java that implements the following logic: Given three ints, `a`

, `b`

, and `c`

, return true if one of `b`

or `c`

is "close" to `a...`

Write a function in Java that implements the following logic: Given 2 `int`

values greater than 0, return whichever value is nearest to 21...

Write a function in Java that implements the following logic: Given three ints, `a`

, `b`

, and `c`

, one of them is small, one is medium and one...

Write a function in Java that implements the following logic: Given a string, return a string made of its first 2 chars. If the string...

Write a function in Java that implements the following logic: Given a string, return a string of length 1 from its front, unless `front`

is...

Write a function in Java called `factorial()`

that will take a positive integer as input and returns its factorial as output.

Write a function in Java that implements the following logic: Given a string and an int `n`

, return a string made of `n`

repetitions of the...

Write a function in Java that implements the following logic: Given a string `str`

and a non-empty `word`

, return a version of the original...

Write a function in Java that implements the following logic: Given two strings, `a`

and `b`

, create a bigger string made of the first...

Given a string `str`

, find all places where a three-letter combination starting with "z" and ending with "p" occurs. Return a string where...

Write a function in Java that implements the following logic: Given a string `str`

and a non-empty `word`

, return a string made of each...

Write a function in Java that counts the number of times the string "code" appears anywhere in the given string `str`

, except that we'll...

Given two strings, return true if either of the strings appears at the very end of the other string, ignoring upper/lower case...

Write a function in Java that returns true if the given string `str`

contains an occurrence of the substring "xyz" where "xyz" is not...

We'll say that a string is *xy-balanced* if for all the 'x' characterss in the string, there exists a 'y' character somewhere later in the...

A sandwich is two pieces of bread with something in between. Write a Java method that takes in a string `str`

and returns the string that...

Given an array containing three ints, return the sum of all the elements.

Given two `int`

arrays `a`

and `b`

, each with two elements, return a new array with four elements containing all the elements of `a`

followed by...

Given an `int`

array of any length, return a new array of its first 2 elements. If the array is smaller than length 2, use whatever...

Write a function in Java that takes an `int`

array as its parameter and returns the number of even `int`

s it contains. Note: the `%`

"mod"...

Write a function in Java that takes an `int`

array as its parameter. It should return the sum of the numbers in the array, except ignore...

We'll say that a value is "everywhere" in an array if for every pair of adjacent elements in the array, at least one of the pair is that...

Given two arrays of the same length, `nums1`

and `nums2`

, for every element in `nums1`

, consider the corresponding element in `nums2`

(at the...

Write a function in Java that returns a version of the given array where all the 10's have been removed. The remaining elements should...

Write a function in Java that takes an array and returns the sum of the numbers in the array, or 0 if the array is empty. Except the...

Given an array of `int`

values, return true if the array contains either 3 even or 3 odd values all next to each other.

For each multiple of 10 in the given array, change all the values following it to be that multiple of 10, until encountering another...

Given an integer array length of 1 or more, return the difference between the largest and smallest values in the array. Note that the...

Return the centered average of an array of `int`

s, which we'll say is the mean average of the values, except ignoring the largest and...

Given a number `n`

, create and return a new `int`

array of length `n`

, containing the numbers 0, 1, 2, ... n-1. The given `n`

may be 0, in which...

Given a number `n`

, create and return a new string array of length `n`

, containing the strings "0", "1" "2" .. through n-1. `N`

may be 0, in...

Given an array of `int`

s, return `true`

if the array contains a 2 next to a 2 somewhere.

Given an array of `int`

s, return `true`

if the array does not contain any 1s or 3s. Otherwise, return `false`

.

Given an array of `int`

s, return `true`

if the sum of all the 2's in the array is exactly 8.

Given an array of `int`

s, return `true`

if the number of 1s is greater than the number of 4s. Otherwise, return `false`

.

Given an array of ints, return `true`

if every element is either a 1 or a 4. Otherwise, return `false`

.

Consider the series of numbers beginning at `start`

and running up to but not including `end`

, so for example start=1 and end=5 gives the...

Given an array of `int`

s, if it contains no 1's return `true`

. If it contains no 4's, return `true`

. If it contains both, return `false`

.

Given an array of `int`

s, return `true`

if the array contains a 2 next to a 2 or a 4 next to a 4, but not both. Otherwise, return `false`

.

Given an array of `int`

s, return `true`

if the array contains two 7s next to each other, or there are two 7s separated by one element, such...

Given an array of `int`

s, return `true`

if there is a 1 in the array with a 2 somewhere later in the array.

Given an array of `int`

s, return `true`

if the value 3 appears in the array exactly 3 times, and no 3s are next to each other.

Given an array of `int`

s, return `true`

if every 2 that appears in the array is next to another 2. Otherwise, return `false`

.

Given a non-empty array, return `true`

if there is a place to split the array so that the sum of the numbers on one side is equal to the...

Consider the leftmost and righmost appearances of some value in an array. We'll say that the *span* is the number of elements between the...

Return an array that contains exactly the same numbers as the given array but re-arranged so that every 3 is immediately followed by a 4....

We'll say that a "mirror" section in an array is a group of contiguous elements such that somewhere in the array, the same group appears...

For this problem, we'll round an `int`

value up to the next multiple of 10 if its rightmost digit is 5 or more, so 15 rounds up to 20....

We want make a package of `goal`

kilos of chocolate. We have small bars (1 kilo each) and big bars (5 kilos each). Return the number of...

Given a string, if the same 2-character substring appears at both its beginning and end, return the contents of the string without the...

Given a string of even length, return the first half. So the string "WooHoo" yields "Woo".

Write a function in Java that implements the following logic: Return a version of the given array where each zero value in the array is...

Given a non-empty array of `int`

s, return a new array containing the elements from the original array that come before the first 4 in the...

Given an array of `int`

values, return true if the group of `n`

numbers at the start of the array is the same as the group of `n`

numbers at...

Say that a "clump" in an array is a series of 2 or more adjacent elements of the same value. Return the number of clumps in the given...

Given an array, return an array that contains exactly the same numbers as the original array, but rearranged so that every 4 is...

Given a string, does "xyz" appear in the middle of the string? To define middle, we'll say that the number of chars to the left and right...

Given a string `str`

and an `int n`

, return a string made of the first `n`

characters of the string, followed by the first `n - 1`

characters of...

Return an array that contains the exact same numbers as the given array, but rearranged so that all the even numbers come before all the...

Given `n`

>= 0, create an array with the pattern {1, 1, 2, 1, 2, 3, ... 1, 2, 3 .. `n`

} (spaces added to show the grouping). Note that...

Given a string of any length, return a new string where the last 2 chars, if present, are swapped, so "coding" yields "codign".

Given a string, return `true`

if "bad" appears starting at index 0 or 1 in the string, such as with "badxxx" or "xbadxx" but not "xxbadxx"....

Return a version of the given string, where for every star (*) in the string the star and the character immediately to its left and the...

Return `true`

if somewhere in the array, there are three increasing adjacent numbers like .... 4, 5, 6, ... or 23, 24, 25.

Given `start`

and `end`

integers, return a new array containing the sequence of integers from `start`

up to but not including `end`

, so `start`

= 5...

Return an array that is "left shifted" by one--so for an input of {6, 2, 5, 3}, the method returns {2, 5, 3, 6}. You may modify and...

Given a non-empty array of `int`

s, return a new array containing the elements from the original array that come after the last 4 in the...

We'll say that an element in an array is "alone" if there are values before and after it, and those values are different from it. Return...

Return an array that contains the exact same numbers as the given array, but rearranged so that all the zeros are grouped at the start of...

Given two arrays of `int`

s sorted in increasing order, called `outer`

and `inner`

, return `true`

if all of the numbers in `inner`

also appear in `...`

Given `n`

>= 0, create an array of length `n * n`

with the following pattern, shown here for `n`

= 3 : {0, 0, 1, 0, 2, 1, 3, 2, 1} (spaces...

Given an `out`

string of length 4, such as "<<>>", and a `word`

, return a new string where the `word`

is in the middle of the `out`

...

Given a string, return a new string made of 3 copies of the last 2 chars of the original string. The string's length will be at least 2.

...Given a string, return the string made of its first two chars, so the string "Hello" yields "He". If the string is shorter than length 2,...

Return `true`

if the string "cat" and "dog" appear the same number of times in the given string.

Return true if the given string contains a "bob" string, but where the middle 'o' character can be any character.

Given two strings, `word`

and a separator `sep`

, return a big string made of `count`

occurrences of the `word`

, separated by the separator...

Given a string, count the number of words ending in 'y' or 'z'--so the 'y' in "heavy" and the 'z' in "fez" count, but not the 'y' in...

We have bunnies standing in a line, numbered 1, 2, ... The odd bunnies (1, 3, 5, ...) have the normal 2 ears. The even bunnies (2, 4,...

Given a non-negative int `n`

, return the sum of its digits recursively (no loops). Note that mod (`%`

) by 10 yields the rightmost digit (126...

Given a non-negative int `n`

, compute recursively (no loops) the count of the occurrences of 8 as a digit, except that an 8 with another 8...

Given an array of `int`

s, compute recursively the number of times that the value 11 appears in the array (no loops). We'll use the...

Given a string, compute recursively a new string where all the adjacent chars are now separated by a "*". So given "hello", return...

Given a string that contains a single pair of parenthesis, compute recursively a new string containing only the parentheses and their...

Given a string and a non-empty substring `sub`

, compute recursively if at least `n`

copies of `sub`

appear in the string somewhere, possibly...

Given a string `str`

and a non-empty substring `sub`

, compute recursively the largest substring which both starts and ends with `sub`

and...

Given a string, return `true`

if it is a nesting of zero or more pairs of parentheses, like "(())" or "((()))". Suggestion: check the first...

Given a string, compute recursively (no loops) the number of times lowercase "hi" appears in the string.

Count recursively (no loops) the total number of "abc" and "aba" substrings that appear in the given string.

Given a string, compute recursively (no loops) a new string where all the lowercase 'x' chars have been changed to 'y' chars.

Given `base`

and `n`

that are both 1 or more, compute recursively (no loops) the value of `base`

to the `n`

power, so `powerN(3, 2)`

is 9 (3...

We'll say that a "pair" in a string is two instances of the same character separated by another character. So in "AxA", the A's make a...

Given a string, return a recursively "cleaned" string where adjacent chars that are the same have been reduced to a single char. So...

Given an array of `int`

s, compute recursively if the array contains somewhere a value followed immediately by that same value times 10....

Given a string, compute recursively a new string where all the 'x' chars have been removed.

Given an array of `int`

s, compute recursively if the array contains a 6. We'll use the convention of considering only the part of the array...

Given a non-negative int `n`

, return the count of the occurrences of 7 as a digit, so for example 717 yields 2. (no loops). Note that mod (...

Given a string, compute recursively (no loops) a new string where all appearances of "pi" have been replaced by "3.14".

Given a day of the week encoded as 0 = Sun, 1 = Mon, 2 = Tue, ... 6 = Sat, and a boolean indicating if we are on vacation, return a...

The number 6 is a truly great number. Given two `int`

values, `a`

and `b`

, return true if either one is 6. Or if their sum or difference is 6....

When squirrels get together for a party, they like to have cigars. A squirrel party is successful when the number of cigars is between 40...

You and your date are trying to get a table at a restaurant. The parameter `you`

is the stylishness of your clothes, in the range 0..10,...

You have a green lottery ticket, with `int`

s `a`

, `b`

, and `c`

on it. If the numbers are all different from each other, the result is 0. If all...

Write a method called `listUpper()`

that takes in a list of strings, and returns a list of the same length containing the same strings but...

Write a method called `listSearch()`

that takes in a target string and a list of other strings. This method returns a (possibly shorter)...

Write a method called `listLength()`

that takes in a list of strings and returns a list of their lengths as integers. You must create a new...

Given a string, return a string where for every char in the original, there are two chars.

Given a string, consider the prefix string made of the first N chars of the string. Does that prefix string appear somewhere else in the...

Given a string, compute a new string by moving the first char to come after the next two chars, so "abc" yields "bca". Repeat this...

Returns true if for every '*' (star) in the string, if there are chars both immediately before and after the star, they are the same.

Given two strings, `base`

and `remove`

, return a version of the `base`

string where all instances of the `remove`

string have been removed (not...

Given a string, return *true* if the number of appearances of "is" anywhere in the string is equal to the number of appearances of "not"...

We'll say that a "triple" in a string is a char appearing three times in a row. Return the number of triples in the given string. The...

We'll say that a lowercase 'g' in a string is "happy" if there is another 'g' immediately to its left or right. Return *true* if all the...

Given a string, return the length of the largest "block" in the string. A block is a run of adjacent chars that are the same.

Given a string, look for a mirror image (backwards) string at both the beginning and end of the given string. In other words, zero or...

Given a string, return the sum of the numbers appearing in the string, ignoring all other characters. A number is a series of 1 or more...

Given a string, return a string where every appearance of the lowercase word "is" has been replaced with "is not". The word "is" should...

Write the missing base case for function 'largest'. Function 'largest' should find the largest number in array "numbers". Note that when...

For function 'multiply', write the missing base case condition and action. This function will multiply two numbers "x" and "y". You can...

The greatest common divisor (GCD) for a pair of numbers is the largest positive integer that divides both numbers without remainder. For...

For function 'log', write the missing base case condition and the recursive call. This function computes the log of "n" to the base "b"....

For function 'sumtok', write the missing recursive call. This function returns the sum of the values from 1 to "k".

For function `addodd()`

write the missing recursive call. This function should return the sum of all postive odd numbers less than or equal...

For function 'sumOfDigits', write the missing recursive call. This function takes a non-negative integer and returns the sum of its...

For function `countChr`

write the missing part of the recursive call. This function should return the number of times that the letter "A"...

For function 'recursiveMin', write the missing part of the recursive call. This function should return the minimum element in an array of...

For function 'isReverse', write the two missing base case conditions. Given two strings, this function returns true if the two strings...

For function 'decToBinary', write the missing parts of the recursion case. This function should return a string that stores the binary...

Spherical objects, such as cannonballs, can be stacked to form a pyramid with one cannonball at the top, sitting on top of a square...

Write a recursive function named 'checkPalindrome' that takes a string as input and returns true if the string is a palindrome and false...

Pascal's triangle is a useful recursive definition that tells us the coefficients in the expansion of the polynomial (x + a)^n. Each...

Write a recursive function that takes a start index, array of integers,and a target sum, your goal is to find whether a subset of of the...

Use appropriate method calls from the List ADT to create the following list: < 4 19| 23 30 > You should assume that L is passed to...

Write a recursive function `BSTsmallcount`

that, given a BST and a value `key`

, returns the number of nodes having values less than `key`

. Your...

Write a recursive function that returns true if there is a node in the given binary tree with the given value, and false otherwise. Note...

Write a recursive function to set the value for each node in a binary tree to be its depth. Assume that nodes store integer values. On...

We define a "root-to-leaf path" to be any sequence of nodes in a tree starting with the root node and proceeding downward to a leaf. The...

Write a recursive function that returns the sum of the values for all of the nodes of the binary tree with root "root".

Given two binary trees, return true if they are structurally identical (they have nodes with the same values, arranged in the same way).

...Use a single assignment statement to make the variable p refer to the Node with info '2' given that the list contains [1,2,3] and points...

Given a binary tree, check if the tree satisfies the property that for each node, the sum of the values of its left and right children...

Given a binary tree, write a recursive function to return the difference between the sum of all node values at odd levels and sum of all...

The height of a binary tree is the length of the path to the deepest node. An empty tree has a height of 0, a tree with one node has a...

Write a recursive function to increment by one the value for every node in the binary tree pointed at by "root" then return the modified...

Write a recursive function to count the number of leaf nodes in the binary tree pointed at by "root". Assume there is "isLeaf" method to...

Given two binary trees, return True if and only if they are mirror images of each other.

Given two binary trees, return True if and only if they are structurally identical (ignoring the content of the nodes).

Write a recursive function `BSTsmallcount`

that, given a BST and a value `key`

, returns the number of nodes having values less than `key`

. Your...

Write a recursive function `BSTsmallcount`

that, given a BST and a value `key`

, returns the number of nodes having values less than `key`

. Your...

`BSTsmallcount`

that, given a BST and a value `key`

, returns the number of nodes having values less than `key`

. Your...

Given a binary tree, check if the tree satisfies the property that for each node, the sum of the values of its left and right children...

Write a recursive function that returns true if there is a node in the given binary tree with the given value, and false otherwise. Note...

Given a binary tree, write a recursive function to return the difference between the sum of all node values at odd levels and sum of all...

The height of a binary tree is the length of the path to the deepest node. An empty tree has a height of 0, a tree with one node has a...

Write a recursive function that increments by one the value for every node in the binary tree pointed at by `root`

, then returns the...

Write a recursive function to count the number of leaf nodes in the binary tree pointed at by `root`

. You must use the `isLeaf`

method to...

We define a "root-to-leaf path" to be any sequence of nodes in a tree starting with the root node and proceeding downward to a leaf. The...

Write a recursive function to set the value for each node in a binary tree to be its depth then return the modified tree. Assume that...

Write a recursive function that returns the sum of the values for all of the nodes of the binary tree with root `root`

.

Here are methods...

Given two binary trees, return true if and only if they are mirror images of each other. Note that two empty trees are considered mirror...

Given two binary trees, return true if they are identical (they have nodes with the same values, arranged in the same way).

Here are...

Given two binary trees, return true if and only if they are structurally identical (they have the same shape, but their nodes can have...

Consider the following class definition:

class Link{

Object data;

Link next;

}

Create a new node with info 'D' and insert it at the end...

Consider the following class definition:

class Link{

Object data;

Link next;

}

Write a while loop to make q refer successively to each...

Consider the following class definition:

class Link{

Object data;

Link next;

}

Link objects can be "linked" together to create a...

Consider the following class definition:

class Link{

Object data;

Link next;

}

List L has a reference to the first node. Write code that...

Consider the following class definition:

class Link{

Object data;

Link next;

}

Return reference to the second to last node (null if list...

Write a member method balanceBags in Java that implements the following logic: Given a String parameter the methods returns the String...

Consider the following class definition:

class Link{

Object data;

Link next;

}

List L has a reference to the first node. Write code that...

Consider the following class definition:

class Link{

Object data;

Link next;

}

List L has a reference to the first node. Write code that...

class Link{

Object data;

Link next;

}

List L has a reference to the first node. Write code that...

class Link{

Object data;

Link next;

}

List L has a reference to the first node. Write code that...

Consider the following class definition:

class Link{

Object data;

Link next;

}

Link p has a reference to the first node. Link ref is a...

Write the member method 'playBagBingo()' that implements the player logic for the game described below. Bag Bingo is a game of chance...

Recall that a Set is an abstract data type somewhat similar to a Bag, they can store a finite collection of objects without any...

class Link{

Object data;

Link next;

}

List L has a reference to the first node. Write code that...

Write an `ArrayBasedStack<T>`

member method called `reverseString()`

that takes a String as a parameter, then uses an ArrayBasedStack...

Write an `ArrayBasedStack<T>`

member method called `decimalToBinary()`

that takes a decimal as an int parameter, then uses an...

Write the ArrayBasedStack member method toArray. The method returns an Object array with a copy of each element in the stack with the top...

Consider the following class definition:

class Link{

Object data;

Link next;

}

Link p has a reference to the first node, of list L....

Write the toString member method that returns the String representation of the items in the bag in the form [item, item, item, item]. For...

Consider the following class definition:

class Link{

Object data;

Link next;

}

Link p has a reference to the first node in list L....

Write the `validateMarkup()`

standalone method to simulate the behavior of real-world tools used to confirm the validity of web pages.

HTML...

Consider the following class definition:

class Link{

Object data;

Link next;

}

Link p has a reference to the first node to list L....

Consider the following class definition:

class Link{

Object data;

Link next;

}

Link p is reference to the first node in a list. Return a...

Consider the following class definition:

class Link{

Object data;

Link next;

}

List L has a reference to the first node. Given a...

Consider the following class definition:

class Link{

Object data;

Link next;

}

Link p has a reference to the first node of List L. Link q...

Write the `toString()`

member method for an ArrayBasedStack. When invoked the method must return the `String`

representation of each entry...

For this question assume the following code:

` public class LinkedBag<T> implements BagInterface<T>{ private Node firstNode; ...`

For this question assume the following code:

` public class LinkedBag<T> implements BagInterface<T>{ private Node firstNode; ...`

For this question assume the following code:

` public class LinkedBag<T> implements BagInterface<T>{ private Node firstNode; ...`

Consider the following class definition:

class Link{

Object data;

Link next;

}

Link p has a reference to the first node of List L. Link q...

For this question assume the following code:

` public class LinkedBag<T> implements BagInterface<T>{ private Node firstNode; ...`

delete this question

For this question assume the following code:

` public class LinkedBag<T> implements BagInterface<T>{ private Node firstNode; ...`

question text goes here