[Based on an exercise at https://codeworkout.cs.vt.edu/]
Given two int
arrays a
and b
, each with two elements, return a new array with...
Exercises
Write a method quicksort that takes in an ArrayList of integers and returns them in ascending order, using a quicksort style of sorting....
Write an algorithm that takes an ArrayList and uses a recursive binary search to return both the index of a given String, or -1 if the...
As a wild publicity stunt May Tricks has made her Middletown store disappear! You have no idea how she did this or if the store will ever...
Since May Tricks has proved to be a very unpredictable client you have decided to take extra precautions. By creating a remove vertex...
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...
[Based on an exercise at https://codeworkout.cs.vt.edu/]
Given an array of Strings, return a single String that is made up of all strings...
[Based on an exercise at https://codeworkout.cs.vt.edu/]
Given an array of int
values, return true if the group of n
numbers at the start...
Design a recursive method for scrambling Strings of length 3 or more. It must swap the first and last character of the input String, then...
There exists an abstract class Bird.
public abstract class Bird { public Bird() {} public String eat() { return "worms"; } public...
Complete the method below for evaluating the substring of any string. If the given string is empty, return "Empty". If the parameters are...
What will be the output of the following code?
public class Answer { System.out.println("Hello World!".substring(6)); }
[Based on an exercise at https://codeworkout.cs.vt.edu/]
Write a function in Java that takes an int
array as its parameter. It should...
[Based on an exercise at https://codeworkout.cs.vt.edu/]
Given an array containing three ints, return the sum of all the elements.
[Based on an exercise at https://codeworkout.cs.vt.edu/]
Write a function in Java that implements the following logic: Given a string,...
A local grocery store has asked you to design a method to verify if their produce is okay to put on the shelves. The method takes an...
The method wabbajack()
is defined as follows:
public String wabbajack(String input) { if (input.length() < 5) { return "Rabbit"; }...
[Based on an exercise at https://codeworkout.cs.vt.edu/]
Write a function in Java that returns a version of the given array where all the...
Write a recursive function int countBTleaves(BinNode root)
to count the number of leaf nodes in the binary tree pointed at by root
. You...
A string is a palindrome if it reads the same forward and backward, with case insensitivity. For example, the words "mom", "dad", "Mom",...
Write a function in Python called 'factorial()' that will take a positive integer as input and returns its factorial as output....
Write a function in C++ called 'factorial' that will take a positive integer as input and returns its factorial. In math, a factorial is...
Write a function in Ruby called 'factorial()' that will take a positive integer as input and returns its factorial as output. backwards.
...Write a function that returns true if a
is even, false otherwise. Just for practice, you must use an if
statement.
This method takes an array of integers as its parameters and returns nothing. The method moves each element in the array to the right by...